Browse Source

fix connections ref

dev
破娃酱 7 years ago
parent
commit
339c1ccee2
  1. 7
      shadowsocks/tcprelay.py

7
shadowsocks/tcprelay.py

@ -138,6 +138,7 @@ class TCPRelayHandler(object):
self._remote_udp = False self._remote_udp = False
self._config = config self._config = config
self._dns_resolver = dns_resolver self._dns_resolver = dns_resolver
self._add_ref = 0
if not self._create_encryptor(config): if not self._create_encryptor(config):
return return
@ -217,6 +218,7 @@ class TCPRelayHandler(object):
self._update_activity() self._update_activity()
self._server.add_connection(1) self._server.add_connection(1)
self._server.stat_add(self._client_address[0], 1) self._server.stat_add(self._client_address[0], 1)
self._add_ref = 1
self.speed_tester_u = SpeedTester(config.get("speed_limit_per_con", 0)) self.speed_tester_u = SpeedTester(config.get("speed_limit_per_con", 0))
self.speed_tester_d = SpeedTester(config.get("speed_limit_per_con", 0)) self.speed_tester_d = SpeedTester(config.get("speed_limit_per_con", 0))
self._recv_u_max_size = BUF_SIZE self._recv_u_max_size = BUF_SIZE
@ -1159,8 +1161,9 @@ class TCPRelayHandler(object):
self._encryptor = None self._encryptor = None
self._dns_resolver.remove_callback(self._handle_dns_resolved) self._dns_resolver.remove_callback(self._handle_dns_resolved)
self._server.remove_handler(self) self._server.remove_handler(self)
self._server.add_connection(-1) if self._add_ref > 0:
self._server.stat_add(self._client_address[0], -1) self._server.add_connection(-1)
self._server.stat_add(self._client_address[0], -1)
class TCPRelay(object): class TCPRelay(object):
def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None): def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None):

Loading…
Cancel
Save