Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2392?usp=email

to review the following change.


Change subject: event: clean up function po_wait
......................................................................

event: clean up function po_wait

- Add early return to remove one level of indentation
- Fix various cast issues, adding required ones and
  removing superfluous ones

Change-Id: I950417b78593c5a04d94112e22cae21419bdc425
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/event.c
1 file changed, 36 insertions(+), 37 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/92/2392/1

diff --git a/src/openvpn/event.c b/src/openvpn/event.c
index 06df285..d083085 100644
--- a/src/openvpn/event.c
+++ b/src/openvpn/event.c
@@ -835,47 +835,46 @@
 po_wait(struct event_set *es, const struct timeval *tv, struct 
event_set_return *out, int outlen)
 {
     struct po_set *pos = (struct po_set *)es;
-    int stat;

-    stat = poll(pos->events, pos->n_events, tv_to_ms_timeout(tv));
-
+    ASSERT(pos->n_events >= 0);
+    int stat = poll(pos->events, (nfds_t)pos->n_events, tv_to_ms_timeout(tv));
     ASSERT(stat <= pos->n_events);
-
-    if (stat > 0)
+    if (stat < 0)
     {
-        int i, j = 0;
-        const struct pollfd *pfdp = pos->events;
-        for (i = 0; i < pos->n_events && j < outlen; ++i)
-        {
-            if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP | 
POLLOUT))
-            {
-                out->rwflags = 0;
-                if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP))
-                {
-                    out->rwflags |= EVENT_READ;
-                }
-                if (pfdp->revents & POLLOUT)
-                {
-                    out->rwflags |= EVENT_WRITE;
-                }
-                out->arg = pos->args[i];
-                dmsg(D_EVENT_WAIT,
-                     "PO_WAIT[%d,%d] fd=%d rev=0x%08x rwflags=0x%04x arg=" 
ptr_format " %s", i, j,
-                     pfdp->fd, pfdp->revents, out->rwflags, (ptr_type)out->arg,
-                     pos->fast ? "" : "[scalable]");
-                ++out;
-                ++j;
-            }
-            else if (pfdp->revents)
-            {
-                msg(D_EVENT_ERRORS, "Error: poll: unknown revents=0x%04x for 
fd=%d",
-                    (unsigned int)pfdp->revents, pfdp->fd);
-            }
-            ++pfdp;
-        }
-        return j;
+        return stat;
     }
-    return stat;
+
+    int j = 0;
+    const struct pollfd *pfdp = pos->events;
+    for (int i = 0; i < pos->n_events && j < outlen; ++i)
+    {
+        if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP | POLLOUT))
+        {
+            out->rwflags = 0;
+            if (pfdp->revents & (POLLIN | POLLPRI | POLLERR | POLLHUP))
+            {
+                out->rwflags |= EVENT_READ;
+            }
+            if (pfdp->revents & POLLOUT)
+            {
+                out->rwflags |= EVENT_WRITE;
+            }
+            out->arg = pos->args[i];
+            dmsg(D_EVENT_WAIT,
+                 "PO_WAIT[%d,%d] fd=%d rev=0x%08x rwflags=0x%04x arg=" 
ptr_format " %s", i, j,
+                 pfdp->fd, pfdp->revents, out->rwflags, (ptr_type)out->arg,
+                 pos->fast ? "" : "[scalable]");
+            ++out;
+            ++j;
+        }
+        else if (pfdp->revents)
+        {
+            msg(D_EVENT_ERRORS, "Error: poll: unknown revents=0x%04x for 
fd=%d",
+                pfdp->revents, pfdp->fd);
+        }
+        ++pfdp;
+    }
+    return j;
 }

 static struct event_set *

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2392?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I950417b78593c5a04d94112e22cae21419bdc425
Gerrit-Change-Number: 2392
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to