From 5e14119b41b7139ff7a5d570003ea3ff4136ff41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=B4=E5=A8=83=E9=85=B1?= Date: Wed, 10 May 2017 20:10:23 +0800 Subject: [PATCH] removefd --- shadowsocks/eventloop.py | 4 ++++ shadowsocks/tcprelay.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/shadowsocks/eventloop.py b/shadowsocks/eventloop.py index d2bbeb6..341620e 100644 --- a/shadowsocks/eventloop.py +++ b/shadowsocks/eventloop.py @@ -176,6 +176,10 @@ class EventLoop(object): del self._fdmap[fd] self._impl.unregister(fd) + def removefd(self, fd): + del self._fdmap[fd] + self._impl.unregister(fd) + def add_periodic(self, callback): self._periodic_callbacks.append(callback) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 414bf43..6ddc531 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -1061,7 +1061,7 @@ class TCPRelayHandler(object): else: logging.warn('unknown socket from %s:%d' % (self._client_address[0], self._client_address[1])) try: - self._loop.remove(sock) + self._loop.removefd(fd) except Exception as e: shell.print_exception(e) try: @@ -1100,7 +1100,7 @@ class TCPRelayHandler(object): if self._remote_sock: logging.debug('destroying remote') try: - self._loop.remove(self._remote_sock) + self._loop.removefd(self._remote_sock_fd) except Exception as e: shell.print_exception(e) try: @@ -1113,7 +1113,7 @@ class TCPRelayHandler(object): if self._remote_sock_v6: logging.debug('destroying remote_v6') try: - self._loop.remove(self._remote_sock_v6) + self._loop.removefd(self._remotev6_sock_fd) except Exception as e: shell.print_exception(e) try: @@ -1126,7 +1126,7 @@ class TCPRelayHandler(object): if self._local_sock: logging.debug('destroying local') try: - self._loop.remove(self._local_sock) + self._loop.removefd(self._local_sock_fd) except Exception as e: shell.print_exception(e) try: @@ -1403,7 +1403,7 @@ class TCPRelay(object): logging.warn('unknown fd') handle = True try: - self._eventloop.remove(sock) + self._eventloop.removefd(fd) except Exception as e: shell.print_exception(e) sock.close()