Merge 3.4 (asyncio)
This commit is contained in:
commit
c27a8afcb0
|
@ -126,14 +126,12 @@ class _BaseWaitHandleFuture(futures.Future):
|
||||||
return
|
return
|
||||||
self._registered = False
|
self._registered = False
|
||||||
|
|
||||||
try:
|
wait_handle = self._wait_handle
|
||||||
_overlapped.UnregisterWait(self._wait_handle)
|
|
||||||
except OSError as exc:
|
|
||||||
self._wait_handle = None
|
self._wait_handle = None
|
||||||
if exc.winerror == _overlapped.ERROR_IO_PENDING:
|
try:
|
||||||
# ERROR_IO_PENDING is not an error, the wait was unregistered
|
_overlapped.UnregisterWait(wait_handle)
|
||||||
self._unregister_wait_cb(None)
|
except OSError as exc:
|
||||||
elif exc.winerror != _overlapped.ERROR_IO_PENDING:
|
if exc.winerror != _overlapped.ERROR_IO_PENDING:
|
||||||
context = {
|
context = {
|
||||||
'message': 'Failed to unregister the wait handle',
|
'message': 'Failed to unregister the wait handle',
|
||||||
'exception': exc,
|
'exception': exc,
|
||||||
|
@ -142,8 +140,9 @@ class _BaseWaitHandleFuture(futures.Future):
|
||||||
if self._source_traceback:
|
if self._source_traceback:
|
||||||
context['source_traceback'] = self._source_traceback
|
context['source_traceback'] = self._source_traceback
|
||||||
self._loop.call_exception_handler(context)
|
self._loop.call_exception_handler(context)
|
||||||
else:
|
return
|
||||||
self._wait_handle = None
|
# ERROR_IO_PENDING means that the unregister is pending
|
||||||
|
|
||||||
self._unregister_wait_cb(None)
|
self._unregister_wait_cb(None)
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
|
@ -209,14 +208,12 @@ class _WaitHandleFuture(_BaseWaitHandleFuture):
|
||||||
return
|
return
|
||||||
self._registered = False
|
self._registered = False
|
||||||
|
|
||||||
try:
|
wait_handle = self._wait_handle
|
||||||
_overlapped.UnregisterWaitEx(self._wait_handle, self._event)
|
|
||||||
except OSError as exc:
|
|
||||||
self._wait_handle = None
|
self._wait_handle = None
|
||||||
if exc.winerror == _overlapped.ERROR_IO_PENDING:
|
try:
|
||||||
# ERROR_IO_PENDING is not an error, the wait was unregistered
|
_overlapped.UnregisterWaitEx(wait_handle, self._event)
|
||||||
self._unregister_wait_cb(None)
|
except OSError as exc:
|
||||||
elif exc.winerror != _overlapped.ERROR_IO_PENDING:
|
if exc.winerror != _overlapped.ERROR_IO_PENDING:
|
||||||
context = {
|
context = {
|
||||||
'message': 'Failed to unregister the wait handle',
|
'message': 'Failed to unregister the wait handle',
|
||||||
'exception': exc,
|
'exception': exc,
|
||||||
|
@ -225,10 +222,10 @@ class _WaitHandleFuture(_BaseWaitHandleFuture):
|
||||||
if self._source_traceback:
|
if self._source_traceback:
|
||||||
context['source_traceback'] = self._source_traceback
|
context['source_traceback'] = self._source_traceback
|
||||||
self._loop.call_exception_handler(context)
|
self._loop.call_exception_handler(context)
|
||||||
else:
|
return
|
||||||
self._wait_handle = None
|
# ERROR_IO_PENDING is not an error, the wait was unregistered
|
||||||
self._event_fut = self._proactor._wait_cancel(
|
|
||||||
self._event,
|
self._event_fut = self._proactor._wait_cancel(self._event,
|
||||||
self._unregister_wait_cb)
|
self._unregister_wait_cb)
|
||||||
|
|
||||||
|
|
||||||
|
@ -409,13 +406,21 @@ class IocpProactor:
|
||||||
self._results = []
|
self._results = []
|
||||||
return tmp
|
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):
|
def recv(self, conn, nbytes, flags=0):
|
||||||
self._register_with_iocp(conn)
|
self._register_with_iocp(conn)
|
||||||
ov = _overlapped.Overlapped(NULL)
|
ov = _overlapped.Overlapped(NULL)
|
||||||
|
try:
|
||||||
if isinstance(conn, socket.socket):
|
if isinstance(conn, socket.socket):
|
||||||
ov.WSARecv(conn.fileno(), nbytes, flags)
|
ov.WSARecv(conn.fileno(), nbytes, flags)
|
||||||
else:
|
else:
|
||||||
ov.ReadFile(conn.fileno(), nbytes)
|
ov.ReadFile(conn.fileno(), nbytes)
|
||||||
|
except BrokenPipeError:
|
||||||
|
return self._result(b'')
|
||||||
|
|
||||||
def finish_recv(trans, key, ov):
|
def finish_recv(trans, key, ov):
|
||||||
try:
|
try:
|
||||||
|
@ -508,9 +513,7 @@ class IocpProactor:
|
||||||
# ConnectNamePipe() failed with ERROR_PIPE_CONNECTED which means
|
# ConnectNamePipe() failed with ERROR_PIPE_CONNECTED which means
|
||||||
# that the pipe is connected. There is no need to wait for the
|
# that the pipe is connected. There is no need to wait for the
|
||||||
# completion of the connection.
|
# completion of the connection.
|
||||||
f = futures.Future(loop=self._loop)
|
return self._result(pipe)
|
||||||
f.set_result(pipe)
|
|
||||||
return f
|
|
||||||
|
|
||||||
def finish_accept_pipe(trans, key, ov):
|
def finish_accept_pipe(trans, key, ov):
|
||||||
ov.getresult()
|
ov.getresult()
|
||||||
|
|
|
@ -730,7 +730,7 @@ Overlapped_ReadFile(OverlappedObject *self, PyObject *args)
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case ERROR_BROKEN_PIPE:
|
case ERROR_BROKEN_PIPE:
|
||||||
mark_as_completed(&self->overlapped);
|
mark_as_completed(&self->overlapped);
|
||||||
Py_RETURN_NONE;
|
return SetFromWindowsErr(err);
|
||||||
case ERROR_SUCCESS:
|
case ERROR_SUCCESS:
|
||||||
case ERROR_MORE_DATA:
|
case ERROR_MORE_DATA:
|
||||||
case ERROR_IO_PENDING:
|
case ERROR_IO_PENDING:
|
||||||
|
@ -789,7 +789,7 @@ Overlapped_WSARecv(OverlappedObject *self, PyObject *args)
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case ERROR_BROKEN_PIPE:
|
case ERROR_BROKEN_PIPE:
|
||||||
mark_as_completed(&self->overlapped);
|
mark_as_completed(&self->overlapped);
|
||||||
Py_RETURN_NONE;
|
return SetFromWindowsErr(err);
|
||||||
case ERROR_SUCCESS:
|
case ERROR_SUCCESS:
|
||||||
case ERROR_MORE_DATA:
|
case ERROR_MORE_DATA:
|
||||||
case ERROR_IO_PENDING:
|
case ERROR_IO_PENDING:
|
||||||
|
|
Loading…
Reference in New Issue