mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
windows, python: Remove code duplication in send/recv functions
Move the return value at the end of the function regardless of the pending/non-pending operation. Signed-off-by: Alin Balutoiu <abalutoiu@cloudbasesolutions.com> Acked-by: Russell Bryant <russell@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
This commit is contained in:
committed by
Alin Gabriel Serdean
parent
e2e31d17f8
commit
ba953e1e83
@@ -321,11 +321,6 @@ class Stream(object):
|
|||||||
self._read,
|
self._read,
|
||||||
False)
|
False)
|
||||||
self._read_pending = False
|
self._read_pending = False
|
||||||
recvBuffer = self._read_buffer[:nBytesRead]
|
|
||||||
# recvBuffer will have the type memoryview in Python3.
|
|
||||||
# We can use bytes to convert it to type bytes which works on
|
|
||||||
# both Python2 and Python3.
|
|
||||||
return (0, bytes(recvBuffer))
|
|
||||||
except pywintypes.error as e:
|
except pywintypes.error as e:
|
||||||
if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
|
if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
|
||||||
# The operation is still pending, try again
|
# The operation is still pending, try again
|
||||||
@@ -336,30 +331,31 @@ class Stream(object):
|
|||||||
return (0, "")
|
return (0, "")
|
||||||
else:
|
else:
|
||||||
return (errno.EINVAL, "")
|
return (errno.EINVAL, "")
|
||||||
(errCode, self._read_buffer) = winutils.read_file(self.pipe,
|
else:
|
||||||
n,
|
(errCode, self._read_buffer) = winutils.read_file(self.pipe,
|
||||||
self._read)
|
n,
|
||||||
if errCode:
|
self._read)
|
||||||
if errCode == winutils.winerror.ERROR_IO_PENDING:
|
if errCode:
|
||||||
self._read_pending = True
|
if errCode == winutils.winerror.ERROR_IO_PENDING:
|
||||||
return (errno.EAGAIN, "")
|
self._read_pending = True
|
||||||
elif errCode in winutils.pipe_disconnected_errors:
|
return (errno.EAGAIN, "")
|
||||||
# If the pipe was disconnected, return 0.
|
elif errCode in winutils.pipe_disconnected_errors:
|
||||||
return (0, "")
|
# If the pipe was disconnected, return 0.
|
||||||
else:
|
return (0, "")
|
||||||
return (errCode, "")
|
else:
|
||||||
|
return (errCode, "")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nBytesRead = winutils.get_overlapped_result(self.pipe,
|
nBytesRead = winutils.get_overlapped_result(self.pipe,
|
||||||
self._read,
|
self._read,
|
||||||
False)
|
False)
|
||||||
winutils.win32event.SetEvent(self._read.hEvent)
|
winutils.win32event.SetEvent(self._read.hEvent)
|
||||||
except pywintypes.error as e:
|
except pywintypes.error as e:
|
||||||
if e.winerror in winutils.pipe_disconnected_errors:
|
if e.winerror in winutils.pipe_disconnected_errors:
|
||||||
# If the pipe was disconnected, return 0.
|
# If the pipe was disconnected, return 0.
|
||||||
return (0, "")
|
return (0, "")
|
||||||
else:
|
else:
|
||||||
return (e.winerror, "")
|
return (e.winerror, "")
|
||||||
|
|
||||||
recvBuffer = self._read_buffer[:nBytesRead]
|
recvBuffer = self._read_buffer[:nBytesRead]
|
||||||
# recvBuffer will have the type memoryview in Python3.
|
# recvBuffer will have the type memoryview in Python3.
|
||||||
@@ -406,7 +402,6 @@ class Stream(object):
|
|||||||
self._write,
|
self._write,
|
||||||
False)
|
False)
|
||||||
self._write_pending = False
|
self._write_pending = False
|
||||||
return nBytesWritten
|
|
||||||
except pywintypes.error as e:
|
except pywintypes.error as e:
|
||||||
if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
|
if e.winerror == winutils.winerror.ERROR_IO_INCOMPLETE:
|
||||||
# The operation is still pending, try again
|
# The operation is still pending, try again
|
||||||
@@ -417,19 +412,18 @@ class Stream(object):
|
|||||||
return -errno.ECONNRESET
|
return -errno.ECONNRESET
|
||||||
else:
|
else:
|
||||||
return -errno.EINVAL
|
return -errno.EINVAL
|
||||||
|
else:
|
||||||
self._write_pending = False
|
(errCode, nBytesWritten) = winutils.write_file(self.pipe,
|
||||||
(errCode, nBytesWritten) = winutils.write_file(self.pipe,
|
buf,
|
||||||
buf,
|
self._write)
|
||||||
self._write)
|
if errCode:
|
||||||
if errCode:
|
if errCode == winutils.winerror.ERROR_IO_PENDING:
|
||||||
if errCode == winutils.winerror.ERROR_IO_PENDING:
|
self._write_pending = True
|
||||||
self._write_pending = True
|
return -errno.EAGAIN
|
||||||
return -errno.EAGAIN
|
if (not nBytesWritten and
|
||||||
if (not nBytesWritten and
|
errCode in winutils.pipe_disconnected_errors):
|
||||||
errCode in winutils.pipe_disconnected_errors):
|
# If the pipe was disconnected, return connection reset.
|
||||||
# If the pipe was disconnected, return connection reset.
|
return -errno.ECONNRESET
|
||||||
return -errno.ECONNRESET
|
|
||||||
return nBytesWritten
|
return nBytesWritten
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user