Rev 6152: Make SmartTCPServer take a client_timeout parameter, which it passes down to the Medium. in http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797
John Arbash Meinel
john at arbash-meinel.com
Thu Sep 15 11:27:36 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797
------------------------------------------------------------
revno: 6152
revision-id: john at arbash-meinel.com-20110915112723-70qvly86obvtmo3z
parent: john at arbash-meinel.com-20110915111230-wzfmwnm7lnltc20i
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: drop-idle-connections-824797
timestamp: Thu 2011-09-15 13:27:23 +0200
message:
Make SmartTCPServer take a client_timeout parameter, which it passes down to the Medium.
-------------- next part --------------
=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py 2011-09-15 09:50:23 +0000
+++ b/bzrlib/smart/server.py 2011-09-15 11:27:23 +0000
@@ -51,7 +51,8 @@
hooks: An instance of SmartServerHooks.
"""
- def __init__(self, backing_transport, root_client_path='/'):
+ def __init__(self, backing_transport, root_client_path='/',
+ client_timeout=None):
"""Construct a new server.
To actually start it running, call either start_background_thread or
@@ -60,9 +61,12 @@
:param backing_transport: The transport to serve.
:param root_client_path: The client path that will correspond to root
of backing_transport.
+ :param client_timeout: See SmartServerSocketStreamMedium's timeout
+ parameter.
"""
self.backing_transport = backing_transport
self.root_client_path = root_client_path
+ self._client_timeout = client_timeout
def start_server(self, host, port):
"""Create the server listening socket.
@@ -179,14 +183,18 @@
"""Return the url of the server"""
return "bzr://%s:%s/" % (self._sockname[0], self._sockname[1])
+ def _create_handler(self, conn):
+ return medium.SmartServerSocketStreamMedium(
+ conn, self.backing_transport, self.root_client_path,
+ timeout=self._client_timeout)
+
def serve_conn(self, conn, thread_name_suffix):
# For WIN32, where the timeout value from the listening socket
# propagates to the newly accepted socket.
conn.setblocking(True)
conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
- handler = medium.SmartServerSocketStreamMedium(
- conn, self.backing_transport, self.root_client_path)
thread_name = 'smart-server-child' + thread_name_suffix
+ handler = self._create_handler(conn)
connection_thread = threading.Thread(
None, handler.serve, name=thread_name)
# FIXME: This thread is never joined, it should at least be collected
=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py 2011-09-15 10:10:11 +0000
+++ b/bzrlib/tests/test_smart_transport.py 2011-09-15 11:27:23 +0000
@@ -1103,6 +1103,18 @@
t.get, 'something')
self.assertContainsRe(str(err), 'some random exception')
+ def test_default_timeout(self):
+ server = _mod_server.SmartTCPServer(None)
+ server_socket = socket.socket()
+ handler = server._create_handler(server_socket)
+ self.assertEqual(handler._DEFAULT_CLIENT_TIMEOUT, handler._client_timeout)
+
+ def test_propagates_timeout(self):
+ server = _mod_server.SmartTCPServer(None, client_timeout=1.23)
+ server_socket = socket.socket()
+ handler = server._create_handler(server_socket)
+ self.assertEqual(1.23, handler._client_timeout)
+
class SmartTCPTests(tests.TestCase):
"""Tests for connection/end to end behaviour using the TCP server.
More information about the bazaar-commits
mailing list