Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
now able to set client_timeout in make_server, fixes #204
Browse files Browse the repository at this point in the history
expose client_timeout settings in thriftpy.rpc helper func
  • Loading branch information
lxyu committed Aug 26, 2016
1 parent a637e00 commit c22ffdc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions thriftpy/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def make_server(service, handler,
host="localhost", port=9090, unix_socket=None,
proto_factory=TBinaryProtocolFactory(),
trans_factory=TBufferedTransportFactory(),
certfile=None):
client_timeout=3000, certfile=None):
processor = TProcessor(service, handler)

if unix_socket:
Expand All @@ -56,10 +56,12 @@ def make_server(service, handler,
warnings.warn("SSL only works with host:port, not unix_socket.")
elif host and port:
if certfile:
server_socket = TSSLServerSocket(host=host, port=port,
certfile=certfile)
server_socket = TSSLServerSocket(
host=host, port=port, client_timeout=client_timeout,
certfile=certfile)
else:
server_socket = TServerSocket(host=host, port=port)
server_socket = TServerSocket(
host=host, port=port, client_timeout=client_timeout)
else:
raise ValueError("Either host/port or unix_socket must be provided.")

Expand Down
3 changes: 2 additions & 1 deletion thriftpy/transport/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def listen(self):

def accept(self):
client, _ = self.sock.accept()
client.settimeout(self.client_timeout)
if self.client_timeout:
client.settimeout(self.client_timeout)
return TSocket(sock=client)

def close(self):
Expand Down
3 changes: 2 additions & 1 deletion thriftpy/transport/sslsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ def accept(self):
sock.close()
raise
else:
ssl_sock.settimeout(self.client_timeout)
if self.client_timeout:
ssl_sock.settimeout(self.client_timeout)
return TSocket(sock=ssl_sock)

0 comments on commit c22ffdc

Please sign in to comment.