… | |
… | |
23 | # elif __freebsd |
23 | # elif __freebsd |
24 | # include <sys/socket.h> |
24 | # include <sys/socket.h> |
25 | # include <sys/uio.h> |
25 | # include <sys/uio.h> |
26 | # elif __hpux |
26 | # elif __hpux |
27 | # include <sys/socket.h> |
27 | # include <sys/socket.h> |
|
|
28 | # elif __solaris /* not yet */ |
|
|
29 | # include <sys/sendfile.h> |
|
|
30 | # else |
|
|
31 | # error sendfile support requested but not available |
28 | # endif |
32 | # endif |
29 | #endif |
33 | #endif |
30 | |
34 | |
31 | #if __ia64 |
35 | #if __ia64 |
32 | # define STACKSIZE 65536 |
36 | # define STACKSIZE 65536 |
… | |
… | |
437 | ssize_t res; |
441 | ssize_t res; |
438 | |
442 | |
439 | if (!count) |
443 | if (!count) |
440 | return 0; |
444 | return 0; |
441 | |
445 | |
|
|
446 | #if HAVE_SENDFILE |
442 | #if __linux |
447 | # if __linux |
443 | res = sendfile (ofd, ifd, &offset, count); |
448 | res = sendfile (ofd, ifd, &offset, count); |
444 | |
449 | |
445 | #elif __freebsd |
450 | # elif __freebsd |
446 | /* |
451 | /* |
447 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
452 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
448 | * wasted on making it similar to other i/o functions. |
453 | * wasted on making it similar to other I/O functions. |
449 | */ |
454 | */ |
450 | { |
455 | { |
451 | off_t sbytes; |
456 | off_t sbytes; |
452 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
457 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
453 | |
458 | |
454 | if (!res && errno == EAGAIN) |
459 | if (res < 0 && sbytes) |
455 | /* maybe on others, too, as usual, the manpage leaves you guessing */ |
460 | /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ |
456 | res = sbytes; |
461 | res = sbytes; |
457 | } |
462 | } |
458 | |
463 | |
459 | #elif __hpux |
464 | # elif __hpux |
460 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
465 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
461 | |
466 | |
|
|
467 | # elif __solaris |
|
|
468 | { |
|
|
469 | struct sendfilevec vec; |
|
|
470 | size_t sbytes; |
|
|
471 | |
|
|
472 | vec.sfv_fd = ifd; |
|
|
473 | vec.sfv_flag = 0; |
|
|
474 | vec.sfv_off = offset; |
|
|
475 | vec.sfv_len = count; |
|
|
476 | |
|
|
477 | res = sendfilev (ofd, &vec, 1, &sbytes); |
|
|
478 | |
|
|
479 | if (res < 0 && sbytes) |
|
|
480 | res = sbytes; |
|
|
481 | } |
|
|
482 | |
462 | #else |
483 | # else |
463 | res = -1; |
484 | res = -1; |
464 | errno = ENOSYS; |
485 | errno = ENOSYS; |
|
|
486 | # endif |
465 | #endif |
487 | #endif |
466 | |
488 | |
|
|
489 | if (res < 0 |
467 | if (res < 0 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK)) |
490 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
|
|
491 | #if __solaris |
|
|
492 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
|
|
493 | #endif |
|
|
494 | ) |
|
|
495 | ) |
468 | { |
496 | { |
469 | /* emulate sendfile. this is a major pain in the ass */ |
497 | /* emulate sendfile. this is a major pain in the ass */ |
470 | char *buf = malloc (4096); |
498 | char *buf = malloc (4096); |
471 | res = 0; |
499 | res = 0; |
472 | |
500 | |