Skip to content

Commit

Permalink
Make recv buffer size a class attribute.
Browse files Browse the repository at this point in the history
This supports overriding it by subclassing, rather than monkey-patching.

Also use a more realistic value in the docs.
  • Loading branch information
aaugustin committed Apr 9, 2023
1 parent 8c6f726 commit a0daea5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/howto/sansio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ When reaching the end of the data stream, call the protocol's
For example, if ``sock`` is a :obj:`~socket.socket`::

try:
data = sock.recv(4096)
data = sock.recv(65536)
except OSError: # socket closed
data = b""
if data:
Expand Down
6 changes: 3 additions & 3 deletions src/websockets/sync/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

logger = logging.getLogger(__name__)

BUFSIZE = 65536


class Connection:
"""
Expand All @@ -39,6 +37,8 @@ class Connection:
"""

recv_bufsize = 65536

def __init__(
self,
socket: socket.socket,
Expand Down Expand Up @@ -525,7 +525,7 @@ def recv_events(self) -> None:
try:
if self.close_deadline is not None:
self.socket.settimeout(self.close_deadline.timeout())
data = self.socket.recv(BUFSIZE)
data = self.socket.recv(self.recv_bufsize)
except Exception as exc:
if self.debug:
self.logger.debug("error while receiving data", exc_info=True)
Expand Down

0 comments on commit a0daea5

Please sign in to comment.