From c7ce8a8343ee19f73df06908014708a0fce6d7fc Mon Sep 17 00:00:00 2001 From: Cheng Liangyu Date: Wed, 25 Apr 2018 17:50:59 +0800 Subject: [PATCH] add SO_KEEPALIVE --- mitmproxy/net/tcp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py index 5e53e398f..220162910 100644 --- a/mitmproxy/net/tcp.py +++ b/mitmproxy/net/tcp.py @@ -563,6 +563,7 @@ class TCPServer: # Only works if self.address == "" self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self.socket.setsockopt(IPPROTO_IPV6, socket.IPV6_V6ONLY, 0) self.socket.bind(self.address) except socket.error: @@ -574,6 +575,7 @@ class TCPServer: # Binding to an IPv6 socket failed, lets fall back to IPv4. self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) self.socket.bind(self.address) self.address = self.socket.getsockname()