--- IO-AIO/AIO.xs 2005/08/22 23:21:57 1.33 +++ IO-AIO/AIO.xs 2005/08/23 01:18:04 1.36 @@ -25,6 +25,10 @@ # include # elif __hpux # include +# elif __solaris /* not yet */ +# include +# else +# error sendfile support requested but not available # endif #endif @@ -439,32 +443,56 @@ if (!count) return 0; -#if __linux +#if HAVE_SENDFILE +# if __linux res = sendfile (ofd, ifd, &offset, count); -#elif __freebsd +# elif __freebsd /* * Of course, the freebsd sendfile is a dire hack with no thoughts - * wasted on making it similar to other i/o functions. + * wasted on making it similar to other I/O functions. */ { off_t sbytes; res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); - if (!res && errno == EAGAIN) - /* maybe on others, too, as usual, the manpage leaves you guessing */ + if (res < 0 && sbytes) + /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ res = sbytes; } -#elif __hpux +# elif __hpux res = sendfile (ofd, ifd, offset, count, 0, 0); -#else +# elif __solaris + { + struct sendfilevec vec; + size_t sbytes; + + vec.sfv_fd = ifd; + vec.sfv_flag = 0; + vec.sfv_off = offset; + vec.sfv_len = count; + + res = sendfilev (ofd, &vec, 1, &sbytes); + + if (res < 0 && sbytes) + res = sbytes; + } + +# else res = -1; errno = ENOSYS; +# endif #endif - if (res < 0 && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK)) + if (res < 0 + && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK +#if __solaris + || errno == EAFNOSUPPORT || errno == EPROTOTYPE +#endif + ) + ) { /* emulate sendfile. this is a major pain in the ass */ char *buf = malloc (4096);