diff options
-rw-r--r-- | include/apr_network_io.h | 7 | ||||
-rw-r--r-- | network_io/beos/poll.c | 19 | ||||
-rw-r--r-- | network_io/os2/poll.c | 7 | ||||
-rw-r--r-- | network_io/unix/poll.c | 27 | ||||
-rw-r--r-- | network_io/win32/poll.c | 32 | ||||
-rw-r--r-- | test/ab_apr.c | 4 |
6 files changed, 51 insertions, 45 deletions
diff --git a/include/apr_network_io.h b/include/apr_network_io.h index 8ad12f643..7068b391e 100644 --- a/include/apr_network_io.h +++ b/include/apr_network_io.h @@ -444,18 +444,19 @@ ap_status_t ap_setup_poll(ap_pollfd_t **new, ap_int32_t num, /* ***APRDOC******************************************************** * ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, - * ap_int32_t timeout) + * ap_interval_time_t timeout) * Poll the sockets in the poll structure. This is a blocking call, * and it will not return until either a socket has been signalled, or * the timeout has expired. * arg 1) The poll structure we will be using. * arg 2) The number of sockets we are polling. - * arg 3) The amount of time in seconds to wait. This is a maximum, not + * arg 3) The amount of time in microseconds to wait. This is a maximum, not * a minimum. If a socket is signalled, we will wake up before this * time. A negative number means wait until a socket is signalled. * NOTE: The number of sockets signalled is returned in the second argument. */ -ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout); +ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, + ap_interval_time_t timeout); /* ***APRDOC******************************************************** * ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, ap_socket_t *sock, diff --git a/network_io/beos/poll.c b/network_io/beos/poll.c index a29c3bf73..ce544f824 100644 --- a/network_io/beos/poll.c +++ b/network_io/beos/poll.c @@ -98,24 +98,23 @@ ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, return APR_SUCCESS; } -ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) +ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, + ap_interval_time_t timeout) { int rv; - struct timeval *thetime; + struct timeval tv, *tvptr; - if (timeout == -1) { - thetime = NULL; + if (timeout < 0) { + tvptr = NULL; } else { - /* Convert milli-seconds into seconds and micro-seconds. */ - thetime = (struct timeval *)ap_palloc(aprset->cntxt, sizeof(struct timeval)); - thetime->tv_sec = timeout / (1000); - timeout = timeout % 1000; - thetime->tv_usec = timeout * 1000; + tv.tv_sec = timeout / AP_USEC_PER_SEC; + tv.tv_usec = timeout % AP_USEC_PER_SEC; + tvptr = &tv; } rv = select(aprset->highsock + 1, aprset->read, aprset->write, - NULL, thetime); + NULL, tvptr); (*nsds) = rv; if ((*nsds) == 0) { diff --git a/network_io/os2/poll.c b/network_io/os2/poll.c index 32dc2bad4..413d876c1 100644 --- a/network_io/os2/poll.c +++ b/network_io/os2/poll.c @@ -126,13 +126,16 @@ ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, -ap_status_t ap_poll(ap_pollfd_t *pollfdset, ap_int32_t *nsds, ap_int32_t timeout) +ap_status_t ap_poll(ap_pollfd_t *pollfdset, ap_int32_t *nsds, + ap_interval_time_t timeout) { int i; int rv = 0; time_t starttime; struct timeval tv; - + + timeout /= AP_USEC_PER_SEC; /* TODO: rework for microseconds and axe this */ + tv.tv_sec = timeout; tv.tv_usec = 0; time(&starttime); diff --git a/network_io/unix/poll.c b/network_io/unix/poll.c index 61fd029fc..c0f39d25f 100644 --- a/network_io/unix/poll.c +++ b/network_io/unix/poll.c @@ -128,7 +128,8 @@ ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, return APR_SUCCESS; } -ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) +ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, + ap_interval_time_t timeout) { int i; struct pollfd *pollset; @@ -142,8 +143,8 @@ ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) pollset[i].events = aprset->events[i]; } - if (timeout != -1) { - timeout *= 1000; + if (timeout > 0) { + timeout /= 1000; /* convert microseconds to milliseconds */ } rv = poll(pollset, aprset->curpos, timeout); @@ -211,6 +212,8 @@ ap_status_t ap_clear_poll_sockets(ap_pollfd_t *aprset, ap_int16_t events) #else /* Use select to mimic poll */ +/* TODO - make this compile and perhaps even work */ + ap_status_t ap_setup_poll(ap_pollfd_t **new, ap_int32_t num, ap_pool_t *cont) { (*new) = (ap_pollfd_t *)ap_palloc(cont, sizeof(ap_pollfd_t) * num); @@ -246,23 +249,23 @@ ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, return APR_SUCCESS; } -ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) +ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, + ap_interval_time_t timeout) { int rv; - struct timeval *thetime; + struct timeval tv, *tvptr; - if (timeout == -1) { - thetime = NULL; + if (timeout < 0) { + tvptr = NULL; } else { - /* Convert milli-seconds into seconds and micro-seconds. */ - thetime = (struct timeval *)ap_palloc(aprset->cntxt, sizeof(struct timeval)); - thetime->tv_sec = timeout; - thetime->tv_usec = 0; + tv.tv_sec = timeout / AP_USEC_PER_SEC; + tv.tv_usec = timeout % AP_USEC_PER_SEC; + tvptr = &tv; } rv = select(aprset->highsock + 1, aprset->read, aprset->write, - aprset->except, thetime); + aprset->except, tvptr); (*nsds) = rv; if ((*nsds) == 0) { diff --git a/network_io/win32/poll.c b/network_io/win32/poll.c index e0fb060f6..c7f13a326 100644 --- a/network_io/win32/poll.c +++ b/network_io/win32/poll.c @@ -98,24 +98,15 @@ ap_status_t ap_add_poll_socket(ap_pollfd_t *aprset, return APR_SUCCESS; } -ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) +ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, + ap_interval_time_t timeout) { int rv; - struct timeval *thetime; + struct timeval tv, *tvptr; fd_set *newread = NULL; fd_set *newwrite = NULL; fd_set *newexcept = NULL; - if (timeout == -1) { - thetime = NULL; - } - else { - /* Convert milli-seconds into seconds and micro-seconds. */ - thetime = (struct timeval *)ap_palloc(aprset->cntxt, sizeof(struct timeval)); - thetime->tv_sec = timeout; - thetime->tv_usec = 0; - } - if (aprset->numread != 0) { newread = aprset->read; } @@ -127,17 +118,26 @@ ap_status_t ap_poll(ap_pollfd_t *aprset, ap_int32_t *nsds, ap_int32_t timeout) } if (newread == NULL && newwrite == NULL && newexcept == NULL) { - Sleep(100); /* Should sleep for timeout, but that will be fixed next */ - return APR_TIMEUP; + Sleep(timeout / 1000); /* convert microseconds into milliseconds */ + return APR_TIMEUP; /* TODO - get everybody in synch with Win32 ap_status_t */ } else { - rv = select(500, newread, newwrite, newexcept, thetime); + if (timeout < 0) { + tvptr = NULL; + } + else { + tv.tv_sec = (long)(timeout / AP_USEC_PER_SEC); + tv.tv_usec = (long)(timeout % AP_USEC_PER_SEC); + tvptr = &tv; + } + rv = select(500, /* ignored on Windows */ + newread, newwrite, newexcept, tvptr); } (*nsds) = rv; if ((*nsds) < 0) { rv = GetLastError(); - return APR_EEXIST; + return APR_EEXIST; /* TODO - get everybody in synch with Win32 ap_status_t */ } return APR_SUCCESS; } diff --git a/test/ab_apr.c b/test/ab_apr.c index 53d284cca..7d36bbca4 100644 --- a/test/ab_apr.c +++ b/test/ab_apr.c @@ -667,7 +667,7 @@ static void read_connection(struct connection *c) static void test(void) { ap_time_t now; - time_t timeout; + ap_interval_time_t timeout; ap_int16_t rv; int i; @@ -742,7 +742,7 @@ static void test(void) requests = done; /* so stats are correct */ } /* Timeout of 30 seconds. */ - timeout = 30; + timeout = 30 * AP_USEC_PER_SEC; n = concurrency; ap_poll(readbits, &n, timeout); |