Support websocket options for cli and infinite time to timeouts (#99)

* add websocket timeout and websocket connetion timeout to Cli. Add support for infinite time to websocket timeout and websocket connection timeout

* change test
This commit is contained in:
Raul 2017-03-25 04:47:59 +01:00 committed by Andrew Godwin
parent d68461920f
commit 9f4f057e4c
3 changed files with 17 additions and 1 deletions

View File

@ -36,6 +36,18 @@ class CommandLineInterface(object):
help='The host/address to bind to', help='The host/address to bind to',
default=None, default=None,
) )
self.parser.add_argument(
'--websocket_timeout',
type=int,
help='max time websocket connected. -1 to infinite.',
default=None,
)
self.parser.add_argument(
'--websocket_connect_timeout',
type=int,
help='max time to refuse establishing connection. -1 to infinite',
default=None,
)
self.parser.add_argument( self.parser.add_argument(
'-u', '-u',
'--unix-socket', '--unix-socket',
@ -186,6 +198,8 @@ class CommandLineInterface(object):
http_timeout=args.http_timeout, http_timeout=args.http_timeout,
ping_interval=args.ping_interval, ping_interval=args.ping_interval,
ping_timeout=args.ping_timeout, ping_timeout=args.ping_timeout,
websocket_timeout=args.websocket_timeout,
websocket_connect_timeout=args.websocket_connect_timeout,
action_logger=AccessLogGenerator(access_log_stream) if access_log_stream else None, action_logger=AccessLogGenerator(access_log_stream) if access_log_stream else None,
ws_protocols=args.ws_protocols, ws_protocols=args.ws_protocols,
root_path=args.root_path, root_path=args.root_path,

View File

@ -385,7 +385,7 @@ class HTTPFactory(http.HTTPFactory):
# WebSocket timeout checking and keepalive ping sending # WebSocket timeout checking and keepalive ping sending
elif isinstance(protocol, WebSocketProtocol): elif isinstance(protocol, WebSocketProtocol):
# Timeout check # Timeout check
if protocol.duration() > self.websocket_timeout: if protocol.duration() > self.websocket_timeout and self.websocket_timeout >= 0:
protocol.serverClose() protocol.serverClose()
# Ping check # Ping check
else: else:

View File

@ -25,6 +25,7 @@ class Server(object):
action_logger=None, action_logger=None,
http_timeout=120, http_timeout=120,
websocket_timeout=None, websocket_timeout=None,
websocket_connect_timeout=None,
ping_interval=20, ping_interval=20,
ping_timeout=30, ping_timeout=30,
ws_protocols=None, ws_protocols=None,
@ -72,6 +73,7 @@ class Server(object):
self.action_logger, self.action_logger,
timeout=self.http_timeout, timeout=self.http_timeout,
websocket_timeout=self.websocket_timeout, websocket_timeout=self.websocket_timeout,
websocket_connect_timeout=self.websocket_connect_timeout,
ping_interval=self.ping_interval, ping_interval=self.ping_interval,
ping_timeout=self.ping_timeout, ping_timeout=self.ping_timeout,
ws_protocols=self.ws_protocols, ws_protocols=self.ws_protocols,