diff options
author | Rafael H. Schloming <rhs@apache.org> | 2011-03-17 12:47:00 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2011-03-17 12:47:00 +0000 |
commit | 887da9b9cbe998b94563ad63be56eae4379e4d0a (patch) | |
tree | a9629b9b10e0c61fa9ca5d6b08b442f59e4a5a56 /python | |
parent | 60de771f86a915a3bacdb8b3bee3738bf4a8887d (diff) | |
download | qpid-python-887da9b9cbe998b94563ad63be56eae4379e4d0a.tar.gz |
added tcp_nodelay connection option
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1082470 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python')
-rw-r--r-- | python/qpid/messaging/driver.py | 2 | ||||
-rw-r--r-- | python/qpid/messaging/endpoints.py | 1 | ||||
-rw-r--r-- | python/qpid/messaging/transports.py | 18 | ||||
-rw-r--r-- | python/qpid/tests/messaging/endpoints.py | 12 |
4 files changed, 20 insertions, 13 deletions
diff --git a/python/qpid/messaging/driver.py b/python/qpid/messaging/driver.py index 91dc5979de..1323e4185c 100644 --- a/python/qpid/messaging/driver.py +++ b/python/qpid/messaging/driver.py @@ -526,7 +526,7 @@ class Driver: rawlog.debug("OPEN[%s]: %s:%s", self.log_id, host, port) trans = transports.TRANSPORTS.get(self.connection.transport) if trans: - self._transport = trans(host, port) + self._transport = trans(self.connection, host, port) else: raise ConnectError("no such transport: %s" % self.connection.transport) if self._retrying and self._reconnect_log: diff --git a/python/qpid/messaging/endpoints.py b/python/qpid/messaging/endpoints.py index 30c5850397..cfc89d4e2b 100644 --- a/python/qpid/messaging/endpoints.py +++ b/python/qpid/messaging/endpoints.py @@ -158,6 +158,7 @@ class Connection(Endpoint): self.reconnect_log = options.get("reconnect_log", True) self.address_ttl = options.get("address_ttl", 60) + self.tcp_nodelay = options.get("tcp_nodelay", False) self.options = options diff --git a/python/qpid/messaging/transports.py b/python/qpid/messaging/transports.py index 8133a45604..7abaae12e8 100644 --- a/python/qpid/messaging/transports.py +++ b/python/qpid/messaging/transports.py @@ -17,18 +17,23 @@ # under the License. # +import socket from qpid.util import connect TRANSPORTS = {} -class tcp: +class SocketTransport: - def __init__(self, host, port): + def __init__(self, conn, host, port): self.socket = connect(host, port) + if conn.tcp_nodelay: + self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) def fileno(self): return self.socket.fileno() +class tcp(SocketTransport): + def reading(self, reading): return reading @@ -52,17 +57,14 @@ try: except ImportError: pass else: - class tls: + class tls(SocketTransport): - def __init__(self, host, port): - self.socket = connect(host, port) + def __init__(self, conn, host, port): + SocketTransport.__init__(self, conn, host, port) self.tls = wrap_socket(self.socket) self.socket.setblocking(0) self.state = None - def fileno(self): - return self.socket.fileno() - def reading(self, reading): if self.state is None: return reading diff --git a/python/qpid/tests/messaging/endpoints.py b/python/qpid/tests/messaging/endpoints.py index 0977b2ab3a..419d0cb395 100644 --- a/python/qpid/tests/messaging/endpoints.py +++ b/python/qpid/tests/messaging/endpoints.py @@ -46,6 +46,10 @@ class SetupTests(Base): self.conn.open() self.ping(self.conn.session()) + def testTcpNodelay(self): + self.conn = Connection.establish(self.broker, tcp_nodelay=True) + assert self.conn._driver._transport.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) + def testConnectError(self): try: # Specifying port 0 yields a bad address on Windows; port 4 is unassigned @@ -111,8 +115,8 @@ class SetupTests(Base): class flaky: - def __init__(self, host, port): - self.real = real(host, port) + def __init__(self, conn, host, port): + self.real = real(conn, host, port) self.sent_count = 0 self.recv_count = 0 @@ -251,8 +255,8 @@ class ConnectionTests(Base): class hangable: - def __init__(self, host, port): - self.tcp = TRANSPORTS["tcp"](host, port) + def __init__(self, conn, host, port): + self.tcp = TRANSPORTS["tcp"](conn, host, port) self.hung = False def hang(self): |