[ovs-dev] [PATCH v2 1/3] poll-loop: Make poll_fd_wait_event() cross-platform.

Gurucharan Shetty shettyg at nicira.com
Mon Feb 10 19:16:20 UTC 2014


This is helpful if we want to wait either on 'fd' for POSIX or
events for Windows.

For Windows, if both 'fd' and 'wevent' is specified, we associate
that event with the 'fd' using WSAEventSelect(). So any 'events'
on that 'fd' will wake us up from WaitForMultipleObjects().

CC: Linda Sun <lsun at vmware.com>
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
 lib/poll-loop.c |   11 +++++++++--
 lib/poll-loop.h |    4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/poll-loop.c b/lib/poll-loop.c
index abd44d1..075aac1 100644
--- a/lib/poll-loop.c
+++ b/lib/poll-loop.c
@@ -81,8 +81,10 @@ find_poll_node(struct poll_loop *loop, int fd, uint32_t wevent)
  *
  * On Windows system:
  *
- *     Register 'wevent' handle for the specified 'events'.  These wevents are
- *     given to the handleMultipleObjects() to be polled.  The event
+ *     If both 'wevent' handle and 'fd' is specified, associate the 'fd' with
+ *     with that 'wevent' for 'events'.  In case of no 'fd' specified, wake
+ *     up on any event on that 'wevent'.  These wevents are
+ *     given to the WaitForMultipleObjects() to be polled.  The event
  *     registration is one-shot: only the following call to poll_block() is
  *     affected.  The event will need to be re-registered after poll_block() is
  *     called if it is to persist.
@@ -119,6 +121,11 @@ poll_fd_wait_at(int fd, HANDLE wevent, short int events, const char *where)
         node->wevent = wevent;
         node->where = where;
     }
+#ifdef _WIN32
+    if (fd && node->wevent) {
+        WSAEventSelect(fd, node->wevent, node->pollfd.events);
+    }
+#endif
 }
 
 /* Causes the following call to poll_block() to block for no more than 'msec'
diff --git a/lib/poll-loop.h b/lib/poll-loop.h
index ae4c0c0..412bd09 100644
--- a/lib/poll-loop.h
+++ b/lib/poll-loop.h
@@ -53,9 +53,9 @@ extern "C" {
 void poll_fd_wait_at(int fd, HANDLE wevent, short int events, const char *where);
 #ifndef _WIN32
 #define poll_fd_wait(fd, events) poll_fd_wait_at(fd, 0, events, SOURCE_LOCATOR)
-#else
-#define poll_fd_wait_event(fd, wevent, events) poll_fd_wait_at(fd, wevent, events, SOURCE_LOCATOR)
 #endif
+#define poll_fd_wait_event(fd, wevent, events)  \
+    poll_fd_wait_at(fd, wevent, events, SOURCE_LOCATOR)
 
 void poll_timer_wait_at(long long int msec, const char *where);
 #define poll_timer_wait(msec) poll_timer_wait_at(msec, SOURCE_LOCATOR)
-- 
1.7.9.5




More information about the dev mailing list