cpython: fb8a093db8b1 (original) (raw)

--- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -78,20 +78,23 @@ class _OverlappedFuture(futures.Future): self._ov = None -class _WaitHandleFuture(futures.Future): +class _BaseWaitHandleFuture(futures.Future): """Subclass of Future which represents a wait handle."""

+ def _poll(self): # non-blocking wait: use a timeout of 0 millisecond return (_winapi.WaitForSingleObject(self._handle, 0) == @@ -99,21 +102,32 @@ class _WaitHandleFuture(futures.Future): def _repr_info(self): info = super()._repr_info()

+ def _unregister_wait(self):

+ try: _overlapped.UnregisterWait(self._wait_handle) except OSError as exc:

@@ -122,26 +136,91 @@ class _WaitHandleFuture(futures.Future): if self._source_traceback: context['source_traceback'] = self._source_traceback self._loop.call_exception_handler(context)

def cancel(self):

def set_exception(self, exception):

def set_result(self, result):

+ + +class _WaitCancelFuture(_BaseWaitHandleFuture):

+

+

+

+ + +class _WaitHandleFuture(_BaseWaitHandleFuture):

+

+

+

+

+

class PipeServer(object): @@ -291,6 +370,7 @@ class IocpProactor: _overlapped.INVALID_HANDLE_VALUE, NULL, 0, concurrency) self._cache = {} self._registered = weakref.WeakSet()

def repr(self): @@ -438,6 +518,16 @@ class IocpProactor: Return a Future object. The result of the future is True if the wait completed, or False if the wait did not complete (on timeout). """

+

+

@@ -447,9 +537,13 @@ class IocpProactor: # We only create ov so we can use ov.address as a key for the cache. ov = _overlapped.Overlapped(NULL)

@@ -462,14 +556,6 @@ class IocpProactor: # False even though we have not timed out. return f._poll()

- self._cache[ov.address] = (f, ov, 0, finish_wait_for_handle) return f @@ -521,6 +607,15 @@ class IocpProactor: self._cache[ov.address] = (f, ov, obj, callback) return f

+

+ def _get_accept_socket(self, family): s = socket.socket(family) s.settimeout(0) @@ -541,7 +636,7 @@ class IocpProactor: while True: status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms) if status is None:

err, transferred, key, address = status @@ -576,6 +671,11 @@ class IocpProactor: f.set_result(value) self._results.append(f)

+ def _stop_serving(self, obj): # obj is a socket or pipe handle. It will be closed in # BaseProactorEventLoop._stop_serving() which will make any

--- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -309,6 +309,29 @@ overlapped_UnregisterWait(PyObject *self Py_RETURN_NONE; } +PyDoc_STRVAR(

+ +static PyObject * +overlapped_UnregisterWaitEx(PyObject *self, PyObject *args) +{

+

+

+

+} + /*