diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 3f063517..6ef9d5cd 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -24,6 +24,8 @@ This library adheres to `Semantic Versioning 2.0 `_. object with a new one rather than clear the old one. - **BACKWARDS INCOMPATIBLE** Removed the ``anyio.create_queue`` function and the ``Queue`` class. Use memory object streams instead. +- **BACKWARDS INCOMPATIBLE** Renamed the ``max_size`` parameter to ``max_bytes`` wherever it + occurred (this was inconsistently named ``max_bytes`` in some subclasses before) - Unified checkpoint behavior: a cancellation check now calls ``sleep(0)`` on asyncio and curio, allowing the scheduler to switch to a different task - Added memory object streams diff --git a/src/anyio/_networking.py b/src/anyio/_networking.py index 54d83e07..2d508ba1 100644 --- a/src/anyio/_networking.py +++ b/src/anyio/_networking.py @@ -259,7 +259,7 @@ async def receive_exactly(self, nbytes: int) -> bytes: self._buffer = self._buffer[nbytes:] return result - async def receive_until(self, delimiter: bytes, max_size: int) -> bytes: + async def receive_until(self, delimiter: bytes, max_bytes: int) -> bytes: delimiter_size = len(delimiter) offset = 0 while True: @@ -271,11 +271,11 @@ async def receive_until(self, delimiter: bytes, max_size: int) -> bytes: return found # Check if the buffer is already at or over the limit - if len(self._buffer) >= max_size: - raise DelimiterNotFound(max_size) + if len(self._buffer) >= max_bytes: + raise DelimiterNotFound(max_bytes) # Read more data into the buffer from the socket - read_size = max_size - len(self._buffer) + read_size = max_bytes - len(self._buffer) data = await self._socket.recv(read_size) if not data: raise IncompleteRead @@ -284,9 +284,9 @@ async def receive_until(self, delimiter: bytes, max_size: int) -> bytes: offset = max(len(self._buffer) - delimiter_size + 1, 0) self._buffer += data - async def receive_chunks(self, max_size: int): + async def receive_chunks(self, max_bytes: int): while True: - data = await self.receive(max_size) + data = await self.receive(max_bytes) if data: yield data else: @@ -447,9 +447,9 @@ async def receive(self, max_bytes: int) -> Tuple[bytes, Tuple[str, int]]: data, addr = await self._socket.recvfrom(max_bytes) return data, addr[:2] - async def receive_packets(self, max_size: int): + async def receive_packets(self, max_bytes: int): while self._socket.fileno() != -1: - packet, address = await self.receive(max_size) + packet, address = await self.receive(max_bytes) if packet: yield (packet, address) else: diff --git a/src/anyio/abc/networking.py b/src/anyio/abc/networking.py index cc3c65cf..a281c808 100644 --- a/src/anyio/abc/networking.py +++ b/src/anyio/abc/networking.py @@ -271,12 +271,13 @@ async def receive(self, max_bytes: int) -> Tuple[bytes, Tuple[str, int]]: """ @abstractmethod - def receive_packets(self, max_size: int) -> AsyncIterable[Tuple[bytes, str]]: + def receive_packets(self, max_bytes: int) -> AsyncIterable[Tuple[bytes, str]]: """ Return an async iterable which yields packets read from the socket. The iterable exits if the socket is closed. + :param max_bytes: maximum number of bytes to return :return: an async iterable yielding (bytes, source address) tuples """