summaryrefslogtreecommitdiff
path: root/poll/os2/pollset.c
diff options
context:
space:
mode:
authorDavid Reid <dreid@apache.org>2003-11-21 19:50:02 +0000
committerDavid Reid <dreid@apache.org>2003-11-21 19:50:02 +0000
commitccd9c1d64839edc381b2d73bf7a0a7b4cdaacb5d (patch)
treed8f9f13c1268ea597e33d17ee309c009e44b4b42 /poll/os2/pollset.c
parent28cdf014e049dce64a9e5fb91075bca29310b34c (diff)
downloadapr-ccd9c1d64839edc381b2d73bf7a0a7b4cdaacb5d.tar.gz
Add back apr_poll as it shouldn't have been removed.
apr_poll is only intended for quick polling. More complex setups should use the pollset structure that now exists. testpoll commit coming shortly to reflect the change and test the pollset code. Brian - can you make sure the OS/2 code is OK? git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64781 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll/os2/pollset.c')
-rw-r--r--poll/os2/pollset.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/poll/os2/pollset.c b/poll/os2/pollset.c
index fd665e5c6..9d8c76a75 100644
--- a/poll/os2/pollset.c
+++ b/poll/os2/pollset.c
@@ -256,3 +256,90 @@ APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset,
*descriptors = pollset->result_set;
return APR_SUCCESS;
}
+
+APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
+ apr_int32_t *nsds, apr_interval_time_t timeout)
+{
+ int *pollset;
+ int i;
+ int num_read = 0, num_write = 0, num_except = 0, num_total;
+ int pos_read, pos_write, pos_except;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ num_read += (aprset[i].reqevents & APR_POLLIN) != 0;
+ num_write += (aprset[i].reqevents & APR_POLLOUT) != 0;
+ num_except += (aprset[i].reqevents & APR_POLLPRI) != 0;
+ }
+ }
+
+ num_total = num_read + num_write + num_except;
+ pollset = alloca(sizeof(int) * num_total);
+ memset(pollset, 0, sizeof(int) * num_total);
+
+ pos_read = 0;
+ pos_write = num_read;
+ pos_except = pos_write + num_write;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ if (aprset[i].reqevents & APR_POLLIN) {
+ pollset[pos_read++] = aprset[i].desc.s->socketdes;
+ }
+
+ if (aprset[i].reqevents & APR_POLLOUT) {
+ pollset[pos_write++] = aprset[i].desc.s->socketdes;
+ }
+
+ if (aprset[i].reqevents & APR_POLLPRI) {
+ pollset[pos_except++] = aprset[i].desc.s->socketdes;
+ }
+
+ aprset[i].rtnevents = 0;
+ }
+ }
+
+ if (timeout > 0) {
+ timeout /= 1000; /* convert microseconds to milliseconds */
+ }
+
+ i = select(pollset, num_read, num_write, num_except, timeout);
+ (*nsds) = i;
+
+ if ((*nsds) < 0) {
+ return APR_FROM_OS_ERROR(sock_errno());
+ }
+
+ if ((*nsds) == 0) {
+ return APR_TIMEUP;
+ }
+
+ pos_read = 0;
+ pos_write = num_read;
+ pos_except = pos_write + num_write;
+
+ for (i = 0; i < num; i++) {
+ if (aprset[i].desc_type == APR_POLL_SOCKET) {
+ if (aprset[i].reqevents & APR_POLLIN) {
+ if (pollset[pos_read++] > 0) {
+ aprset[i].rtnevents |= APR_POLLIN;
+ }
+ }
+
+ if (aprset[i].reqevents & APR_POLLOUT) {
+ if (pollset[pos_write++] > 0) {
+ aprset[i].rtnevents |= APR_POLLOUT;
+ }
+ }
+
+ if (aprset[i].reqevents & APR_POLLPRI) {
+ if (pollset[pos_except++] > 0) {
+ aprset[i].rtnevents |= APR_POLLPRI;
+ }
+ }
+ }
+ }
+
+ return APR_SUCCESS;
+}
+