[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] sendfile on solaris



In addition to my note about 64-bit offsets earlier:

Solaris sendfile seems to fail when sending moderately large (<1GB) files. Not a 32/64 problem, but a buffer problem.
Anyone else ever try this? It is definitely broken in http-server.c.

It seems to be broken in the following way:
When sendfile sends partial data (EAGAIN, would block), "res" is always -1, rather than the amount sent. Here's a patch that reads from the "offset" pointer instead to discover what was sent. This seems to work:

--- buffer.c    2010-12-16 10:05:27.000000000 -0800
+++ ../libevent/buffer.c        2011-08-11 14:13:42.288328799 -0700
@@ -2262,11 +2262,18 @@
        }
        return (res);
 #elif defined(SENDFILE_IS_SOLARIS)
-       res = sendfile(fd, info->fd, &offset, chain->off);
-       if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
+
+       off_t offset0 = offset;
+       res = sendfile(fd, info->fd, &offset, chain->off);
+
+       if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) {
+               if (offset - offset0) {
+                       return offset - offset0;
+               }
                /* if this is EAGAIN or EINTR return 0; otherwise, -1 */
                return (0);
-       }
+       }
+
        return (res);
 #endif
 }


mike

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.