Klaus Demo ~jonashaag/bjoern / 4cf7058
introduce listen_backlog option Fabien MARTY 1 year, 6 months ago
1 changed file(s) with 9 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
33
44
55 _default_instance = None
6 LISTEN_BACKLOG = 1024
6 DEFAULT_LISTEN_BACKLOG = 1024
77
88
9 def bind_and_listen(host, port=None, reuse_port=False):
9 def bind_and_listen(host, port=None, reuse_port=False,
10 listen_backlog=DEFAULT_LISTEN_BACKLOG):
1011 if host.startswith("unix:@"):
1112 # Abstract UNIX socket: "unix:@foobar"
1213 sock = socket.socket(socket.AF_UNIX)
2829 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
2930 sock.bind((host, port))
3031
31 sock.listen(LISTEN_BACKLOG)
32 sock.listen(listen_backlog)
3233
3334 return sock
3435
3839
3940
4041 # Backwards compatibility API
41 def listen(wsgi_app, host, port=None, reuse_port=False):
42 def listen(wsgi_app, host, port=None, reuse_port=False,
43 listen_backlog=DEFAULT_LISTEN_BACKLOG):
4244 """
4345 Makes bjoern listen to 'host:port' and use 'wsgi_app' as WSGI application.
4446 (This does not run the server mainloop.)
4547
4648 'reuse_port' -- whether to set SO_REUSEPORT (if available on platform)
49 'listen_backlog' -- listen backlog value (default: 1024)
4750 """
4851 global _default_instance
4952 if _default_instance:
5053 raise RuntimeError("Only one global server instance possible")
51 sock = bind_and_listen(host, port, reuse_port)
54 sock = bind_and_listen(host, port, reuse_port,
55 listen_backlog=listen_backlog)
5256 _default_instance = (sock, wsgi_app)
5357
5458