apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Andrews <effb...@gmail.com>
Subject Re: struct apr_pollset_private_t
Date Wed, 17 Jun 2009 09:10:30 GMT
On Wed, Jun 17, 2009 at 2:54 AM, Bojan Smojver<bojan@rexursive.com> wrote:
> On Tue, 2009-06-16 at 00:41 +0200, Jack Andrews wrote:
>> feedback welcome - it can probably be improved
>
> Did you really want to use functions for casting?

removed the casting functions:

Index: pushtest/exapr/include/arch/unix/apr_arch_poll_private.h
===================================================================
--- pushtest.orig/exapr/include/arch/unix/apr_arch_poll_private.h	2009-03-06
02:38:58.000000000 +0100
+++ pushtest/exapr/include/arch/unix/apr_arch_poll_private.h	2009-06-16
00:04:17.173000000 +0200
@@ -104,7 +104,6 @@

 #endif

-typedef struct apr_pollset_private_t apr_pollset_private_t;
 typedef struct apr_pollset_provider_t apr_pollset_provider_t;
 typedef struct apr_pollcb_provider_t apr_pollcb_provider_t;
 struct apr_pollset_t
@@ -115,7 +114,7 @@
     apr_uint32_t flags;
     /* Pipe descriptors used for wakeup */
     apr_file_t *wakeup_pipe[2];
-    apr_pollset_private_t *p;
+    void *p;
     apr_pollset_provider_t *provider;
 };

Index: pushtest/exapr/poll/unix/poll.c
===================================================================
--- pushtest.orig/exapr/poll/unix/poll.c	2009-03-03 01:29:22.000000000 +0100
+++ pushtest/exapr/poll/unix/poll.c	2009-06-17 11:07:08.322000000 +0200
@@ -147,7 +147,7 @@

 #endif /* POLL_USES_POLL */

-struct apr_pollset_private_t
+struct apr_poll_pollset_t
 {
     struct pollfd *pollset;
     apr_pollfd_t *query_set;
@@ -159,6 +159,8 @@
                                         apr_pool_t *p,
                                         apr_uint32_t flags)
 {
+    struct apr_poll_pollset_t **pollset_p =
+      (struct apr_poll_pollset_t **)&pollset->p;
     if (flags & APR_POLLSET_THREADSAFE) {
         return APR_ENOTIMPL;
     }
@@ -167,10 +169,10 @@
         return APR_ENOTIMPL;
     }
 #endif
-    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
-    pollset->p->pollset = apr_palloc(p, size * sizeof(struct pollfd));
-    pollset->p->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
-    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+    *pollset_p = apr_palloc(p, sizeof(struct apr_poll_pollset_t));
+    (*pollset_p)->pollset = apr_palloc(p, size * sizeof(struct pollfd));
+    (*pollset_p)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+    (*pollset_p)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));

     return APR_SUCCESS;
 }
@@ -178,14 +180,16 @@
 static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
                                      const apr_pollfd_t *descriptor)
 {
+    struct apr_poll_pollset_t *pollset_p =
+      (struct apr_poll_pollset_t *)pollset->p;
     if (pollset->nelts == pollset->nalloc) {
         return APR_ENOMEM;
     }

-    pollset->p->query_set[pollset->nelts] = *descriptor;
+    pollset_p->query_set[pollset->nelts] = *descriptor;

     if (descriptor->desc_type == APR_POLL_SOCKET) {
-        pollset->p->pollset[pollset->nelts].fd = descriptor->desc.s->socketdes;
+        pollset_p->pollset[pollset->nelts].fd = descriptor->desc.s->socketdes;
     }
     else {
 #if APR_FILES_AS_SOCKETS
@@ -193,12 +197,12 @@
 #else
         if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
             descriptor->desc.f == pollset->wakeup_pipe[0])
-            pollset->p->pollset[pollset->nelts].fd =
(SOCKET)descriptor->desc.f->filedes;
+            pollset_p->pollset[pollset->nelts].fd =
(SOCKET)descriptor->desc.f->filedes;
         else
             return APR_EBADF;
 #endif
     }
-    pollset->p->pollset[pollset->nelts].events =
+    pollset_p->pollset[pollset->nelts].events =
         get_event(descriptor->reqevents);
     pollset->nelts++;

@@ -209,20 +213,22 @@
                                         const apr_pollfd_t *descriptor)
 {
     apr_uint32_t i;
+    struct apr_poll_pollset_t *pollset_p =
+      (struct apr_poll_pollset_t *)pollset->p;

     for (i = 0; i < pollset->nelts; i++) {
-        if (descriptor->desc.s == pollset->p->query_set[i].desc.s) {
+        if (descriptor->desc.s == pollset_p->query_set[i].desc.s) {
             /* Found an instance of the fd: remove this and any other copies */
             apr_uint32_t dst = i;
             apr_uint32_t old_nelts = pollset->nelts;
             pollset->nelts--;
             for (i++; i < old_nelts; i++) {
-                if (descriptor->desc.s == pollset->p->query_set[i].desc.s) {
+                if (descriptor->desc.s == pollset_p->query_set[i].desc.s) {
                     pollset->nelts--;
                 }
                 else {
-                    pollset->p->pollset[dst] = pollset->p->pollset[i];
-                    pollset->p->query_set[dst] = pollset->p->query_set[i];
+                    pollset_p->pollset[dst] = pollset_p->pollset[i];
+                    pollset_p->query_set[dst] = pollset_p->query_set[i];
                     dst++;
                 }
             }
@@ -241,14 +247,16 @@
     int ret;
     apr_status_t rv = APR_SUCCESS;
     apr_uint32_t i, j;
+    struct apr_poll_pollset_t *pollset_p =
+      (struct apr_poll_pollset_t *)pollset->p;

     if (timeout > 0) {
         timeout /= 1000;
     }
 #ifdef WIN32
-    ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
+    ret = WSAPoll(pollset_p->pollset, pollset->nelts, (int)timeout);
 #else
-    ret = poll(pollset->p->pollset, pollset->nelts, timeout);
+    ret = poll(pollset_p->pollset, pollset->nelts, timeout);
 #endif
     (*num) = ret;
     if (ret < 0) {
@@ -259,20 +267,20 @@
     }
     else {
         for (i = 0, j = 0; i < pollset->nelts; i++) {
-            if (pollset->p->pollset[i].revents != 0) {
+            if (pollset_p->pollset[i].revents != 0) {
                 /* Check if the polled descriptor is our
                  * wakeup pipe. In that case do not put it result set.
                  */
                 if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
-                    pollset->p->query_set[i].desc_type == APR_POLL_FILE &&
-                    pollset->p->query_set[i].desc.f ==
pollset->wakeup_pipe[0]) {
+                    pollset_p->query_set[i].desc_type == APR_POLL_FILE &&
+                    pollset_p->query_set[i].desc.f ==
pollset->wakeup_pipe[0]) {
                         apr_pollset_drain_wakeup_pipe(pollset);
                         rv = APR_EINTR;
                 }
                 else {
-                    pollset->p->result_set[j] = pollset->p->query_set[i];
-                    pollset->p->result_set[j].rtnevents =
-                        get_revent(pollset->p->pollset[i].revents);
+                    pollset_p->result_set[j] = pollset_p->query_set[i];
+                    pollset_p->result_set[j].rtnevents =
+                        get_revent(pollset_p->pollset[i].revents);
                     j++;
                 }
             }
@@ -281,7 +289,7 @@
             rv = APR_SUCCESS;
     }
     if (descriptors && (*num))
-        *descriptors = pollset->p->result_set;
+        *descriptors = pollset_p->result_set;
     return rv;
 }

Index: pushtest/exapr/poll/unix/select.c
===================================================================
--- pushtest.orig/exapr/poll/unix/select.c	2009-06-16 00:32:35.000000000 +0200
+++ pushtest/exapr/poll/unix/select.c	2009-06-17 11:07:03.103000000 +0200
@@ -167,7 +167,7 @@

 #endif /* POLL_USES_SELECT */

-struct apr_pollset_private_t
+struct apr_select_pollset_t
 {
     fd_set readset, writeset, exceptset;
     int maxfd;
@@ -184,26 +184,28 @@
                                         apr_pool_t *p,
                                         apr_uint32_t flags)
 {
+    struct apr_select_pollset_t **pollset_p =
+      (struct apr_select_pollset_t **)&pollset->p;
     if (flags & APR_POLLSET_THREADSAFE) {
-        pollset->p = NULL;
+        *pollset_p = NULL;
         return APR_ENOTIMPL;
     }
 #ifdef FD_SETSIZE
     if (size > FD_SETSIZE) {
-        pollset->p = NULL;
+        pollset_p = NULL;
         return APR_EINVAL;
     }
 #endif
-    pollset->p = apr_palloc(p, sizeof(struct apr_pollset_private_t));
-    FD_ZERO(&(pollset->p->readset));
-    FD_ZERO(&(pollset->p->writeset));
-    FD_ZERO(&(pollset->p->exceptset));
-    pollset->p->maxfd = 0;
+    *pollset_p = apr_palloc(p, sizeof(struct apr_select_pollset_t));
+    FD_ZERO(&((*pollset_p)->readset));
+    FD_ZERO(&((*pollset_p)->writeset));
+    FD_ZERO(&((*pollset_p)->exceptset));
+    (*pollset_p)->maxfd = 0;
 #ifdef NETWARE
-    pollset->p->set_type = APR_NO_DESC;
+    pollset_p->set_type = APR_NO_DESC;
 #endif
-    pollset->p->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
-    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+    (*pollset_p)->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+    (*pollset_p)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));

     return APR_SUCCESS;
 }
@@ -212,21 +214,23 @@
                                      const apr_pollfd_t *descriptor)
 {
     apr_os_sock_t fd;
+    struct apr_select_pollset_t *pollset_p =
+      (struct apr_select_pollset_t *)pollset->p;

     if (pollset->nelts == pollset->nalloc) {
         return APR_ENOMEM;
     }

-    pollset->p->query_set[pollset->nelts] = *descriptor;
+    pollset_p->query_set[pollset->nelts] = *descriptor;

     if (descriptor->desc_type == APR_POLL_SOCKET) {
 #ifdef NETWARE
         /* NetWare can't handle mixed descriptor types in select() */
-        if (HAS_PIPES(pollset->p->set_type)) {
+        if (HAS_PIPES(pollset_p->set_type)) {
             return APR_EBADF;
         }
         else {
-            pollset->p->set_type = APR_POLL_SOCKET;
+            pollset_p->set_type = APR_POLL_SOCKET;
         }
 #endif
         fd = descriptor->desc.s->socketdes;
@@ -241,8 +245,8 @@
 #else
 #ifdef NETWARE
         /* NetWare can't handle mixed descriptor types in select() */
-        if (descriptor->desc.f->is_pipe &&
!HAS_SOCKETS(pollset->p->set_type)) {
-            pollset->p->set_type = APR_POLL_FILE;
+        if (descriptor->desc.f->is_pipe && !HAS_SOCKETS(pollset_p->set_type))
{
+            pollset_p->set_type = APR_POLL_FILE;
             fd = descriptor->desc.f->filedes;
         }
         else {
@@ -260,17 +264,17 @@
     }
 #endif
     if (descriptor->reqevents & APR_POLLIN) {
-        FD_SET(fd, &(pollset->p->readset));
+        FD_SET(fd, &(pollset_p->readset));
     }
     if (descriptor->reqevents & APR_POLLOUT) {
-        FD_SET(fd, &(pollset->p->writeset));
+        FD_SET(fd, &(pollset_p->writeset));
     }
     if (descriptor->reqevents &
         (APR_POLLPRI | APR_POLLERR | APR_POLLHUP | APR_POLLNVAL)) {
-        FD_SET(fd, &(pollset->p->exceptset));
+        FD_SET(fd, &(pollset_p->exceptset));
     }
-    if ((int) fd > pollset->p->maxfd) {
-        pollset->p->maxfd = (int) fd;
+    if ((int) fd > pollset_p->maxfd) {
+        pollset_p->maxfd = (int) fd;
     }
     pollset->nelts++;
     return APR_SUCCESS;
@@ -281,6 +285,8 @@
 {
     apr_uint32_t i;
     apr_os_sock_t fd;
+    struct apr_select_pollset_t *pollset_p =
+      (struct apr_select_pollset_t *)pollset->p;

     if (descriptor->desc_type == APR_POLL_SOCKET) {
         fd = descriptor->desc.s->socketdes;
@@ -294,25 +300,25 @@
     }

     for (i = 0; i < pollset->nelts; i++) {
-        if (descriptor->desc.s == pollset->p->query_set[i].desc.s) {
+        if (descriptor->desc.s == pollset_p->query_set[i].desc.s) {
             /* Found an instance of the fd: remove this and any other copies */
             apr_uint32_t dst = i;
             apr_uint32_t old_nelts = pollset->nelts;
             pollset->nelts--;
             for (i++; i < old_nelts; i++) {
-                if (descriptor->desc.s == pollset->p->query_set[i].desc.s) {
+                if (descriptor->desc.s == pollset_p->query_set[i].desc.s) {
                     pollset->nelts--;
                 }
                 else {
-                    pollset->p->query_set[dst] = pollset->p->query_set[i];
+                    pollset_p->query_set[dst] = pollset_p->query_set[i];
                     dst++;
                 }
             }
-            FD_CLR(fd, &(pollset->p->readset));
-            FD_CLR(fd, &(pollset->p->writeset));
-            FD_CLR(fd, &(pollset->p->exceptset));
-            if (((int) fd == pollset->p->maxfd) && (pollset->p->maxfd
> 0)) {
-                pollset->p->maxfd--;
+            FD_CLR(fd, &(pollset_p->readset));
+            FD_CLR(fd, &(pollset_p->writeset));
+            FD_CLR(fd, &(pollset_p->exceptset));
+            if (((int) fd == pollset_p->maxfd) && (pollset_p->maxfd > 0))
{
+                pollset_p->maxfd--;
             }
             return APR_SUCCESS;
         }
@@ -331,6 +337,8 @@
     struct timeval tv, *tvptr;
     fd_set readset, writeset, exceptset;
     apr_status_t rv = APR_SUCCESS;
+    struct apr_select_pollset_t *pollset_p =
+      (struct apr_select_pollset_t *)pollset->p;

 #ifdef WIN32
     /* On Win32, select() must be presented with at least one socket to
@@ -352,18 +360,18 @@
         tvptr = &tv;
     }

-    memcpy(&readset, &(pollset->p->readset), sizeof(fd_set));
-    memcpy(&writeset, &(pollset->p->writeset), sizeof(fd_set));
-    memcpy(&exceptset, &(pollset->p->exceptset), sizeof(fd_set));
+    memcpy(&readset, &(pollset_p->readset), sizeof(fd_set));
+    memcpy(&writeset, &(pollset_p->writeset), sizeof(fd_set));
+    memcpy(&exceptset, &(pollset_p->exceptset), sizeof(fd_set));

 #ifdef NETWARE
-    if (HAS_PIPES(pollset->p->set_type)) {
-        rs = pipe_select(pollset->p->maxfd + 1, &readset, &writeset,
&exceptset,
+    if (HAS_PIPES(pollset_p->set_type)) {
+        rs = pipe_select(pollset_p->maxfd + 1, &readset, &writeset, &exceptset,
                          tvptr);
     }
     else
 #endif
-        rs = select(pollset->p->maxfd + 1, &readset, &writeset, &exceptset,
+        rs = select(pollset_p->maxfd + 1, &readset, &writeset, &exceptset,
                     tvptr);

     (*num) = rs;
@@ -376,12 +384,12 @@
     j = 0;
     for (i = 0; i < pollset->nelts; i++) {
         apr_os_sock_t fd;
-        if (pollset->p->query_set[i].desc_type == APR_POLL_SOCKET) {
-            fd = pollset->p->query_set[i].desc.s->socketdes;
+        if (pollset_p->query_set[i].desc_type == APR_POLL_SOCKET) {
+            fd = pollset_p->query_set[i].desc.s->socketdes;
         }
         else {
             if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
-                pollset->p->query_set[i].desc.f == pollset->wakeup_pipe[0]) {
+                pollset_p->query_set[i].desc.f == pollset->wakeup_pipe[0]) {
                 apr_pollset_drain_wakeup_pipe(pollset);
                 rv = APR_EINTR;
                 continue;
@@ -390,22 +398,22 @@
 #if !APR_FILES_AS_SOCKETS
                 return APR_EBADF;
 #else
-                fd = pollset->p->query_set[i].desc.f->filedes;
+                fd = pollset_p->query_set[i].desc.f->filedes;
 #endif
             }
         }
         if (FD_ISSET(fd, &readset) || FD_ISSET(fd, &writeset) ||
             FD_ISSET(fd, &exceptset)) {
-            pollset->p->result_set[j] = pollset->p->query_set[i];
-            pollset->p->result_set[j].rtnevents = 0;
+            pollset_p->result_set[j] = pollset_p->query_set[i];
+            pollset_p->result_set[j].rtnevents = 0;
             if (FD_ISSET(fd, &readset)) {
-                pollset->p->result_set[j].rtnevents |= APR_POLLIN;
+                pollset_p->result_set[j].rtnevents |= APR_POLLIN;
             }
             if (FD_ISSET(fd, &writeset)) {
-                pollset->p->result_set[j].rtnevents |= APR_POLLOUT;
+                pollset_p->result_set[j].rtnevents |= APR_POLLOUT;
             }
             if (FD_ISSET(fd, &exceptset)) {
-                pollset->p->result_set[j].rtnevents |= APR_POLLERR;
+                pollset_p->result_set[j].rtnevents |= APR_POLLERR;
             }
             j++;
         }
@@ -414,7 +422,7 @@
         rv = APR_SUCCESS;

     if (descriptors)
-        *descriptors = pollset->p->result_set;
+        *descriptors = pollset_p->result_set;
     return rv;
 }

Mime
View raw message