apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject [PATCH] speed up network timeout processing
Date Wed, 03 Jul 2002 11:56:44 GMT
A little bird told me that FD_ZERO() burns lots of cycles in
apr_wait_for_io_or_timeout().  It turns out that this is an easy
conversion to poll(), which doesn't have such overhead in the
interface.

This works for me with some testing (timeouts on read and write work
for me).

--- /tmp/sendrecv.c     Wed Jul  3 07:19:33 2002
+++ network_io/unix/sendrecv.c  Wed Jul  3 06:42:41 2002
@@ -61,6 +61,33 @@
 
 apr_status_t apr_wait_for_io_or_timeout(apr_socket_t *sock, int for_read)
 {
+#ifdef HAVE_POLL
+    int rc, timeout;
+    struct pollfd fd;
+
+    if (sock->timeout < 0) {
+        timeout = -1;
+    }
+    else {
+        timeout = sock->timeout / 1000; /* convert usecs to msecs */
+    }
+
+    fd.fd = sock->socketdes;
+    fd.events = for_read ? POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI :
+        POLLOUT;
+
+    do {
+        rc = poll(&fd, 1, timeout);
+    } while (rc == -1 && errno == EINTR);
+
+    if (rc == 0) {
+        return APR_TIMEUP;
+    }
+    else if (rc < 0) {
+        return errno;
+    }
+    return APR_SUCCESS;
+#else /* HAVE_POLL */
     struct timeval tv, *tvptr;
     fd_set fdset;
     int srv;
@@ -91,6 +118,7 @@
         return errno;
     }
     return APR_SUCCESS;
+#endif /* HAVE_POLL */
 }
 
 apr_status_t apr_send(apr_socket_t *sock, const char *buf, apr_size_t *len)
-- 
Jeff Trawick | trawick@attglobal.net
Born in Roswell... married an alien...

Mime
View raw message