summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-26 22:07:16 +0100
committerVictor Stinner <victor.stinner@gmail.com>2015-01-26 22:07:16 +0100
commit31fa887dbd1e6c89728b0ed99f7974266852d3a8 (patch)
tree8d4929447b2a8a727ab18f87b7267e5612f23fb9
parent6e1910bb8aaa1149bb7ebb7aba3c0c73a5522262 (diff)
downloadtrollius-31fa887dbd1e6c89728b0ed99f7974266852d3a8.tar.gz
Tulip issue #204: Fix IocpProactor.recv()
If ReadFile() fails with ERROR_BROKEN_PIPE, the operation is not pending: don't register the overlapped. I don't know if WSARecv() can fail with ERROR_BROKEN_PIPE. Since Overlapped.WSARecv() already handled ERROR_BROKEN_PIPE, let me guess that it has the same behaviour than ReadFile().
-rw-r--r--asyncio/windows_events.py20
-rw-r--r--overlapped.c4
2 files changed, 15 insertions, 9 deletions
diff --git a/asyncio/windows_events.py b/asyncio/windows_events.py
index 8f1d9d2..94aafb6 100644
--- a/asyncio/windows_events.py
+++ b/asyncio/windows_events.py
@@ -406,13 +406,21 @@ class IocpProactor:
self._results = []
return tmp
+ def _result(self, value):
+ fut = futures.Future(loop=self._loop)
+ fut.set_result(value)
+ return fut
+
def recv(self, conn, nbytes, flags=0):
self._register_with_iocp(conn)
ov = _overlapped.Overlapped(NULL)
- if isinstance(conn, socket.socket):
- ov.WSARecv(conn.fileno(), nbytes, flags)
- else:
- ov.ReadFile(conn.fileno(), nbytes)
+ try:
+ if isinstance(conn, socket.socket):
+ ov.WSARecv(conn.fileno(), nbytes, flags)
+ else:
+ ov.ReadFile(conn.fileno(), nbytes)
+ except BrokenPipeError:
+ return self._result(b'')
def finish_recv(trans, key, ov):
try:
@@ -505,9 +513,7 @@ class IocpProactor:
# ConnectNamePipe() failed with ERROR_PIPE_CONNECTED which means
# that the pipe is connected. There is no need to wait for the
# completion of the connection.
- f = futures.Future(loop=self._loop)
- f.set_result(pipe)
- return f
+ return self._result(pipe)
def finish_accept_pipe(trans, key, ov):
ov.getresult()
diff --git a/overlapped.c b/overlapped.c
index 4661152..1a081ec 100644
--- a/overlapped.c
+++ b/overlapped.c
@@ -730,7 +730,7 @@ Overlapped_ReadFile(OverlappedObject *self, PyObject *args)
switch (err) {
case ERROR_BROKEN_PIPE:
mark_as_completed(&self->overlapped);
- Py_RETURN_NONE;
+ return SetFromWindowsErr(err);
case ERROR_SUCCESS:
case ERROR_MORE_DATA:
case ERROR_IO_PENDING:
@@ -789,7 +789,7 @@ Overlapped_WSARecv(OverlappedObject *self, PyObject *args)
switch (err) {
case ERROR_BROKEN_PIPE:
mark_as_completed(&self->overlapped);
- Py_RETURN_NONE;
+ return SetFromWindowsErr(err);
case ERROR_SUCCESS:
case ERROR_MORE_DATA:
case ERROR_IO_PENDING: