From 4a291ff335ada38d061c1e1eb7b20e192dece6d4 Mon Sep 17 00:00:00 2001 From: BreakWa11 Date: Fri, 29 Jul 2016 17:19:30 +0800 Subject: [PATCH] add keep alive setting --- shadowsocks/tcprelay.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index ef9a1c1..e70de02 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -563,6 +563,11 @@ class TCPRelayHandler(object): remote_sock_v6.setblocking(False) else: remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) + remote_sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) + remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 120) + remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 20) + remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, 5) + if not self._is_local: bind_addr = '' if self._bind and af == socket.AF_INET: