apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r806192 - in /apr/apr/branches/1.3.x: CHANGES poll/unix/port.c
Date Thu, 20 Aug 2009 14:39:39 GMT
Author: trawick
Date: Thu Aug 20 14:39:39 2009
New Revision: 806192

URL: http://svn.apache.org/viewvc?rev=806192&view=rev
Log:
backport the following relatively simple Event Port fixes from trunk:

r749049
commentary, consistency, simplification, and minor fixes

impl_pollset_create():
. return the actual port_create() failure instead of APR_ENOMEM

impl_pollset_add():
. return the actual port_associate() failure instead of APR_ENOMEM

impl_pollset_poll():
. catch port_associate() failures
. don't report returned events to caller unless something popped
 besides the wakeup pipe

impl_pollcb_poll():
. fix incorrect mapping of EINTR onto APR_TIMEUP
. don't hide interesting error codes behind APR_EGENERAL

generally:
. axe redundant APR_RING_EMPTY() invocations
. don't check for EINTR explicitly, as it is handled appropriately
 by the apr_get_netos_error() invocation (IOW, EINTR == APR_EINTR here)

r749490 (only the port.c portion)
pollset tweaks:
 axe logic to set ignored conditions in the poll request structures
 (these conditions are return-only and are always reported when
 they occur)

r750279
don't lose track of a ring element when port_associate() fails

r754294 (only the port.c portion)
nelts, the number of elements in the pollset, was neither needed
nor properly maintained by these implementations, so axe the
related code

Additional, more complex fixes only in trunk at this point:
 r750277, r750708, r750744

Modified:
    apr/apr/branches/1.3.x/CHANGES
    apr/apr/branches/1.3.x/poll/unix/port.c

Modified: apr/apr/branches/1.3.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/CHANGES?rev=806192&r1=806191&r2=806192&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.3.x/CHANGES [utf-8] Thu Aug 20 14:39:39 2009
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.3.9
 
+  *) Fix error handling in the Solaris poll support (Event Port).  [Jeff
+     Trawick]
+
   *) Add the remainder of this fix from trunk:
      Fix Solaris poll failure.  PR 43000
      [Henry Jen <henryjen ztune.net>]

Modified: apr/apr/branches/1.3.x/poll/unix/port.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/poll/unix/port.c?rev=806192&r1=806191&r2=806192&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/poll/unix/port.c (original)
+++ apr/apr/branches/1.3.x/poll/unix/port.c Thu Aug 20 14:39:39 2009
@@ -30,12 +30,7 @@
         rv |= POLLPRI;
     if (event & APR_POLLOUT)
         rv |= POLLOUT;
-    if (event & APR_POLLERR)
-        rv |= POLLERR;
-    if (event & APR_POLLHUP)
-        rv |= POLLHUP;
-    if (event & APR_POLLNVAL)
-        rv |= POLLNVAL;
+    /* POLLERR, POLLHUP, and POLLNVAL aren't valid as requested events */
 
     return rv;
 }
@@ -64,7 +59,6 @@
 struct apr_pollset_t
 {
     apr_pool_t *pool;
-    apr_uint32_t nelts;
     apr_uint32_t nalloc;
     int port_fd;
     port_event_t *port_set;
@@ -76,6 +70,9 @@
 #endif
     /* A ring containing all of the pollfd_t that are active */
     APR_RING_HEAD(pfd_query_ring_t, pfd_elem_t) query_ring;
+    /* A ring containing the pollfd_t that will be added on the
+     * next call to apr_pollset_poll().
+     */
     APR_RING_HEAD(pfd_add_ring_t, pfd_elem_t) add_ring;
     /* A ring of pollfd_t that have been used, and then _remove'd */
     APR_RING_HEAD(pfd_free_ring_t, pfd_elem_t) free_ring;
@@ -115,7 +112,6 @@
     }
 #endif
     (*pollset)->waiting = 0;
-    (*pollset)->nelts = 0;
     (*pollset)->nalloc = size;
     (*pollset)->flags = flags;
     (*pollset)->pool = p;
@@ -125,7 +121,7 @@
     (*pollset)->port_fd = port_create();
 
     if ((*pollset)->port_fd < 0) {
-        return APR_ENOMEM;
+        return apr_get_netos_error();
     }
 
     {
@@ -184,21 +180,22 @@
         fd = descriptor->desc.f->filedes;
     }
 
+    /* If another thread is polling, notify the kernel immediately; otherwise,
+     * wait until the next call to apr_pollset_poll().
+     */
     if (apr_atomic_read32(&pollset->waiting)) {
         res = port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, 
                              get_event(descriptor->reqevents), (void *)elem);
 
         if (res < 0) {
-            rv = APR_ENOMEM;
+            rv = apr_get_netos_error();
             APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link);
         }
         else {
-            pollset->nelts++;
             APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link);
         }
     } 
     else {
-        pollset->nelts++;
         APR_RING_INSERT_TAIL(&(pollset->add_ring), elem, pfd_elem_t, link);
     }
 
@@ -232,39 +229,35 @@
         rv = APR_NOTFOUND;
     }
 
-    if (!APR_RING_EMPTY(&(pollset->query_ring), pfd_elem_t, link)) {
-        for (ep = APR_RING_FIRST(&(pollset->query_ring));
-             ep != APR_RING_SENTINEL(&(pollset->query_ring),
-                                     pfd_elem_t, link);
-             ep = APR_RING_NEXT(ep, link)) {
-
-            if (descriptor->desc.s == ep->pfd.desc.s) {
-                APR_RING_REMOVE(ep, link);
-                APR_RING_INSERT_TAIL(&(pollset->dead_ring),
-                                     ep, pfd_elem_t, link);
-                if (ENOENT == err) {
-                    rv = APR_SUCCESS;
-                }
-                break;
+    for (ep = APR_RING_FIRST(&(pollset->query_ring));
+         ep != APR_RING_SENTINEL(&(pollset->query_ring),
+                                 pfd_elem_t, link);
+         ep = APR_RING_NEXT(ep, link)) {
+
+        if (descriptor->desc.s == ep->pfd.desc.s) {
+            APR_RING_REMOVE(ep, link);
+            APR_RING_INSERT_TAIL(&(pollset->dead_ring),
+                                 ep, pfd_elem_t, link);
+            if (ENOENT == err) {
+                rv = APR_SUCCESS;
             }
+            break;
         }
     }
 
-    if (!APR_RING_EMPTY(&(pollset->add_ring), pfd_elem_t, link)) {
-        for (ep = APR_RING_FIRST(&(pollset->add_ring));
-             ep != APR_RING_SENTINEL(&(pollset->add_ring),
-                                     pfd_elem_t, link);
-             ep = APR_RING_NEXT(ep, link)) {
-
-            if (descriptor->desc.s == ep->pfd.desc.s) {
-                APR_RING_REMOVE(ep, link);
-                APR_RING_INSERT_TAIL(&(pollset->dead_ring),
-                                     ep, pfd_elem_t, link);
-                if (ENOENT == err) {
-                    rv = APR_SUCCESS;
-                }
-                break;
+    for (ep = APR_RING_FIRST(&(pollset->add_ring));
+         ep != APR_RING_SENTINEL(&(pollset->add_ring),
+                                 pfd_elem_t, link);
+         ep = APR_RING_NEXT(ep, link)) {
+
+        if (descriptor->desc.s == ep->pfd.desc.s) {
+            APR_RING_REMOVE(ep, link);
+            APR_RING_INSERT_TAIL(&(pollset->dead_ring),
+                                 ep, pfd_elem_t, link);
+            if (ENOENT == err) {
+                rv = APR_SUCCESS;
             }
+            break;
         }
     }
 
@@ -311,15 +304,24 @@
             fd = ep->pfd.desc.f->filedes;
         }
 
-        port_associate(pollset->port_fd, PORT_SOURCE_FD, 
-                           fd, get_event(ep->pfd.reqevents), ep);
+        ret = port_associate(pollset->port_fd, PORT_SOURCE_FD, 
+                             fd, get_event(ep->pfd.reqevents), ep);
+        if (ret < 0) {
+            rv = apr_get_netos_error();
+            APR_RING_INSERT_TAIL(&(pollset->free_ring), ep, pfd_elem_t, link);
+            break;
+        }
 
         APR_RING_INSERT_TAIL(&(pollset->query_ring), ep, pfd_elem_t, link);
-
     }
 
     pollset_unlock_rings();
 
+    if (rv != APR_SUCCESS) {
+        apr_atomic_dec32(&pollset->waiting);
+        return rv;
+    }
+
     ret = port_getn(pollset->port_fd, pollset->port_set, pollset->nalloc,
                     &nget, tvptr);
 
@@ -330,14 +332,11 @@
 
     if (ret == -1) {
         (*num) = 0;
-        if (errno == EINTR) {
-            rv = APR_EINTR;
-        }
-        else if (errno == ETIME) {
+        if (errno == ETIME) {
             rv = APR_TIMEUP;
         }
         else {
-            rv = APR_EGENERAL;
+            rv = apr_get_netos_error();
         }
     }
     else if (nget == 0) {
@@ -367,10 +366,9 @@
         }
     }
 
-
     pollset_lock_rings();
 
-    /* Shift all PFDs in the Dead Ring to be Free Ring */
+    /* Shift all PFDs in the Dead Ring to the Free Ring */
     APR_RING_CONCAT(&(pollset->free_ring), &(pollset->dead_ring), pfd_elem_t,
link);
 
     pollset_unlock_rings();
@@ -494,11 +492,11 @@
                     &nget, tvptr);
 
     if (ret == -1) {
-        if (errno == ETIME || errno == EINTR) {
+        if (errno == ETIME) {
             rv = APR_TIMEUP;
         }
         else {
-            rv = APR_EGENERAL;
+            rv = apr_get_netos_error();
         }
     }
     else if (nget == 0) {



Mime
View raw message