[ovs-dev] [PATCH 2/2] windows,python: remove unnecessary code

Alin Balutoiu abalutoiu at cloudbasesolutions.com
Fri Aug 25 15:02:57 UTC 2017


At the moment we have WSAEventSelect in each if branch.

Since the call to the function is similar, we can move
it outside the if branch and create some local variables
which will be passed to WSAEventSelect.

This patch also remove the keyword argument passed when
the event for the connection overlapped structure is created.
The argument is not needed since it does not change the value
from the default one.

Signed-off-by: Alin Balutoiu <abalutoiu at cloudbasesolutions.com>
---
 python/ovs/stream.py | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)

diff --git a/python/ovs/stream.py b/python/ovs/stream.py
index 9d0536d..cb1cdbe 100644
--- a/python/ovs/stream.py
+++ b/python/ovs/stream.py
@@ -457,29 +457,24 @@ class Stream(object):
     def __wait_windows(self, poller, wait):
         if self.socket is not None:
             if wait == Stream.W_RECV:
-                read_flags = (win32file.FD_READ |
-                              win32file.FD_ACCEPT |
-                              win32file.FD_CLOSE)
-                try:
-                    win32file.WSAEventSelect(self.socket,
-                                             self._wevent,
-                                             read_flags)
-                except pywintypes.error as e:
-                    vlog.err("failed to associate events with socket: %s"
-                             % e.strerror)
-                poller.fd_wait(self._wevent, ovs.poller.POLLIN)
+                mask = (win32file.FD_READ |
+                        win32file.FD_ACCEPT |
+                        win32file.FD_CLOSE)
+                event = ovs.poller.POLLIN
             else:
-                write_flags = (win32file.FD_WRITE |
-                               win32file.FD_CONNECT |
-                               win32file.FD_CLOSE)
-                try:
-                    win32file.WSAEventSelect(self.socket,
-                                             self._wevent,
-                                             write_flags)
-                except pywintypes.error as e:
-                    vlog.err("failed to associate events with socket: %s"
-                             % e.strerror)
-                poller.fd_wait(self._wevent, ovs.poller.POLLOUT)
+                mask = (win32file.FD_WRITE |
+                        win32file.FD_CONNECT |
+                        win32file.FD_CLOSE)
+                event = ovs.poller.POLLOUT
+
+            try:
+                win32file.WSAEventSelect(self.socket,
+                                         self._wevent,
+                                         mask)
+            except pywintypes.error as e:
+                vlog.err("failed to associate events with socket: %s"
+                         % e.strerror)
+            poller.fd_wait(self._wevent, event)
         else:
             if wait == Stream.W_RECV:
                 if self._read:
@@ -549,7 +544,7 @@ class PassiveStream(object):
         self.socket = sock
         if pipe is not None:
             self.connect = pywintypes.OVERLAPPED()
-            self.connect.hEvent = winutils.get_new_event(bManualReset=True)
+            self.connect.hEvent = winutils.get_new_event()
             self.connect_pending = False
             suffix = name.split(":", 1)[1]
             suffix = ovs.util.abs_file_name(ovs.dirs.RUNDIR, suffix)
-- 
2.10.0.windows.1


More information about the dev mailing list