From 22da0af45a89b4167a9c13e860fcc455efa23bd6 Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Mon, 3 Oct 2011 11:03:34 +0200 Subject: [PATCH] Addded an option (default disabled) to enable tcp keepalive --- sjrpc/core/rpcconnection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index 48c1836..57664a6 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -59,7 +59,8 @@ class RpcConnection(object): 'write': select.POLLOUT, 'hup': select.POLLHUP, 'error': select.POLLERR | select.POLLNVAL} - def __init__(self, sock, loop=None, *args, **kwargs): + def __init__(self, sock, loop=None, enable_tcp_keepalive=False, + *args, **kwargs): # Sock of this connection: self._sock = sock sock.setblocking(False) @@ -71,7 +72,8 @@ class RpcConnection(object): self.loop = loop # Activate TCP keepalive on the connection: - #self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) + if enable_tcp_keepalive: + self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # Watcher list: self._watchers = set() -- GitLab