diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index e85634e588f5a5..a6d7e1b408fce9 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -463,10 +463,10 @@ def remove_writer(self, fd): # Completion based I/O methods returning Futures. - def sock_recv(self, sock, nbytes): + def sock_recv(self, sock, nbytes, flags=0): raise NotImplementedError - def sock_sendall(self, sock, data): + def sock_sendall(self, sock, data, flags=0): raise NotImplementedError def sock_connect(self, sock, address): diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 9dbe550b01774a..33aea139ec4dd4 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -351,7 +351,7 @@ def remove_writer(self, fd): self._ensure_fd_no_transport(fd) return self._remove_writer(fd) - def sock_recv(self, sock, n): + def sock_recv(self, sock, n, flags=0): """Receive data from the socket. The return value is a bytes object representing the data received. @@ -363,10 +363,10 @@ def sock_recv(self, sock, n): if self._debug and sock.gettimeout() != 0: raise ValueError("the socket must be non-blocking") fut = self.create_future() - self._sock_recv(fut, False, sock, n) + self._sock_recv(fut, False, sock, n, flags) return fut - def _sock_recv(self, fut, registered, sock, n): + def _sock_recv(self, fut, registered, sock, n, flags=0): # _sock_recv() can add itself as an I/O callback if the operation can't # be done immediately. Don't use it directly, call sock_recv(). fd = sock.fileno() @@ -379,15 +379,15 @@ def _sock_recv(self, fut, registered, sock, n): if fut.cancelled(): return try: - data = sock.recv(n) + data = sock.recv(n, flags) except (BlockingIOError, InterruptedError): - self.add_reader(fd, self._sock_recv, fut, True, sock, n) + self.add_reader(fd, self._sock_recv, fut, True, sock, n, flags) except Exception as exc: fut.set_exception(exc) else: fut.set_result(data) - def sock_sendall(self, sock, data): + def sock_sendall(self, sock, data, flags=0): """Send data to the socket. The socket must be connected to a remote socket. This method continues @@ -402,12 +402,12 @@ def sock_sendall(self, sock, data): raise ValueError("the socket must be non-blocking") fut = self.create_future() if data: - self._sock_sendall(fut, False, sock, data) + self._sock_sendall(fut, False, sock, data, flags) else: fut.set_result(None) return fut - def _sock_sendall(self, fut, registered, sock, data): + def _sock_sendall(self, fut, registered, sock, data, flags=0): fd = sock.fileno() if registered: @@ -416,7 +416,7 @@ def _sock_sendall(self, fut, registered, sock, data): return try: - n = sock.send(data) + n = sock.send(data, flags) except (BlockingIOError, InterruptedError): n = 0 except Exception as exc: