Skip to content

Commit

Permalink
Pass arguments to create_server/connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jan 20, 2024
1 parent cba4c24 commit cd4bc79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/websockets/sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def connect(
the connection. Set it to a wrapper or a subclass to customize
connection handling.
Any other keyword arguments are passed to :func:`~socket.create_connection`.
Raises:
InvalidURI: If ``uri`` isn't a valid WebSocket URI.
OSError: If the TCP connection fails.
Expand Down Expand Up @@ -245,10 +247,8 @@ def connect(
assert path is not None # mypy cannot figure this out
sock.connect(path)
else:
sock = socket.create_connection(
(wsuri.host, wsuri.port),
deadline.timeout(),
)
kwargs.setdefault("timeout", deadline.timeout())
sock = socket.create_connection((wsuri.host, wsuri.port), **kwargs)
sock.settimeout(None)

# Disable Nagle algorithm
Expand Down
8 changes: 6 additions & 2 deletions src/websockets/sync/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def handler(websocket):
create_connection: Factory for the :class:`ServerConnection` managing
the connection. Set it to a wrapper or a subclass to customize
connection handling.
Any other keyword arguments are passed to :func:`~socket.create_server`.
"""

# Process parameters
Expand All @@ -404,9 +407,10 @@ def handler(websocket):
if unix:
if path is None:
raise TypeError("missing path argument")
sock = socket.create_server(path, family=socket.AF_UNIX)
kwargs.setdefault("family", socket.AF_UNIX)
sock = socket.create_server(path, **kwargs)
else:
sock = socket.create_server((host, port))
sock = socket.create_server((host, port), **kwargs)
else:
if path is not None:
raise TypeError("path and sock arguments are incompatible")
Expand Down

0 comments on commit cd4bc79

Please sign in to comment.