diff mbox

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

Message ID 1503673364-3166-3-git-send-email-abalutoiu@cloudbasesolutions.com
State Accepted
Headers show

Commit Message

Alin Balutoiu Aug. 25, 2017, 3:02 p.m. UTC
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@cloudbasesolutions.com>
---
 python/ovs/stream.py | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)

Comments

Alin-Gabriel Serdean Aug. 29, 2017, 7:58 a.m. UTC | #1
Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>


> -----Original Message-----
> From: ovs-dev-bounces@openvswitch.org [mailto:ovs-dev-
> bounces@openvswitch.org] On Behalf Of Alin Balutoiu
> Sent: Friday, August 25, 2017 6:03 PM
> To: dev@openvswitch.org
> Subject: [ovs-dev] [PATCH 2/2] windows,python: remove unnecessary code
> 
> 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@cloudbasesolutions.com>
> ---
>  python/ovs/stream.py | 41 ++++++++++++++++++-----------------------
>  1 file changed, 18 insertions(+), 23 deletions(-)
>
diff mbox

Patch

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)