@@ -245,22 +245,37 @@ def wait_closed(self):
245
245
246
246
@asyncio .coroutine
247
247
def serve (ws_handler , host = None , port = None , * ,
248
- loop = None , klass = WebSocketServerProtocol , legacy_recv = False ,
248
+ klass = WebSocketServerProtocol ,
249
+ timeout = 10 , max_size = 2 ** 20 , max_queue = 2 ** 5 ,
250
+ loop = None , legacy_recv = False ,
249
251
origins = None , subprotocols = None , extra_headers = None ,
250
252
** kwds ):
251
253
"""
252
254
This coroutine creates a WebSocket server.
253
255
254
- It's a wrapper around the event loop's
255
- :meth:`~asyncio.BaseEventLoop.create_server` method. ``host``, ``port`` as
256
- well as extra keyword arguments are passed to
257
- :meth:`~asyncio.BaseEventLoop.create_server`. For example, you can set the
258
- ``ssl`` keyword argument to a :class:`~ssl.SSLContext` to enable TLS.
256
+ It yields a :class:`~asyncio.Server` which provides:
257
+
258
+ * a :meth:`~asyncio.Server.close` method that closes open connections with
259
+ status code 1001 and stops accepting new connections
260
+ * a :meth:`~asyncio.Server.wait_closed` coroutine that waits until closing
261
+ handshakes complete and connections are closed.
259
262
260
263
``ws_handler`` is the WebSocket handler. It must be a coroutine accepting
261
264
two arguments: a :class:`WebSocketServerProtocol` and the request URI.
262
265
263
- :func:`serve` accepts several optional arguments:
266
+ :func:`serve` is a wrapper around the event loop's
267
+ :meth:`~asyncio.BaseEventLoop.create_server` method. ``host``, ``port`` as
268
+ well as extra keyword arguments are passed to
269
+ :meth:`~asyncio.BaseEventLoop.create_server`.
270
+
271
+ For example, you can set the ``ssl`` keyword argument to a
272
+ :class:`~ssl.SSLContext` to enable TLS.
273
+
274
+ The behavior of the ``timeout``, ``max_size``, and ``max_queue`` optional
275
+ arguments is described the documentation of
276
+ :class:`~websockets.protocol.WebSocketCommonProtocol`.
277
+
278
+ :func:`serve` also accepts the following optional arguments:
264
279
265
280
* ``origins`` defines acceptable Origin HTTP headers — include
266
281
``''`` if the lack of an origin is acceptable
@@ -270,13 +285,6 @@ def serve(ws_handler, host=None, port=None, *,
270
285
mapping, an iterable of (name, value) pairs, or a callable taking the
271
286
request path and headers in arguments.
272
287
273
- :func:`serve` yields a :class:`~asyncio.Server` which provides:
274
-
275
- * a :meth:`~asyncio.Server.close` method that closes open connections with
276
- status code 1001 and stops accepting new connections
277
- * a :meth:`~asyncio.Server.wait_closed` coroutine that waits until closing
278
- handshakes complete and connections are closed.
279
-
280
288
Whenever a client connects, the server accepts the connection, creates a
281
289
:class:`WebSocketServerProtocol`, performs the opening handshake, and
282
290
delegates to the WebSocket handler. Once the handler completes, the server
@@ -301,8 +309,11 @@ def serve(ws_handler, host=None, port=None, *,
301
309
factory = lambda : klass (
302
310
ws_handler , ws_server ,
303
311
host = host , port = port , secure = secure ,
312
+ timeout = timeout , max_size = max_size , max_queue = max_queue ,
313
+ loop = loop , legacy_recv = legacy_recv ,
304
314
origins = origins , subprotocols = subprotocols ,
305
- extra_headers = extra_headers , loop = loop , legacy_recv = legacy_recv )
315
+ extra_headers = extra_headers ,
316
+ )
306
317
server = yield from loop .create_server (factory , host , port , ** kwds )
307
318
308
319
ws_server .wrap (server )
0 commit comments