This commit is contained in:
破娃酱 2017-05-10 20:10:23 +08:00
parent a1f56d1233
commit 5e14119b41
2 changed files with 9 additions and 5 deletions

View file

@ -176,6 +176,10 @@ class EventLoop(object):
del self._fdmap[fd] del self._fdmap[fd]
self._impl.unregister(fd) self._impl.unregister(fd)
def removefd(self, fd):
del self._fdmap[fd]
self._impl.unregister(fd)
def add_periodic(self, callback): def add_periodic(self, callback):
self._periodic_callbacks.append(callback) self._periodic_callbacks.append(callback)

View file

@ -1061,7 +1061,7 @@ class TCPRelayHandler(object):
else: else:
logging.warn('unknown socket from %s:%d' % (self._client_address[0], self._client_address[1])) logging.warn('unknown socket from %s:%d' % (self._client_address[0], self._client_address[1]))
try: try:
self._loop.remove(sock) self._loop.removefd(fd)
except Exception as e: except Exception as e:
shell.print_exception(e) shell.print_exception(e)
try: try:
@ -1100,7 +1100,7 @@ class TCPRelayHandler(object):
if self._remote_sock: if self._remote_sock:
logging.debug('destroying remote') logging.debug('destroying remote')
try: try:
self._loop.remove(self._remote_sock) self._loop.removefd(self._remote_sock_fd)
except Exception as e: except Exception as e:
shell.print_exception(e) shell.print_exception(e)
try: try:
@ -1113,7 +1113,7 @@ class TCPRelayHandler(object):
if self._remote_sock_v6: if self._remote_sock_v6:
logging.debug('destroying remote_v6') logging.debug('destroying remote_v6')
try: try:
self._loop.remove(self._remote_sock_v6) self._loop.removefd(self._remotev6_sock_fd)
except Exception as e: except Exception as e:
shell.print_exception(e) shell.print_exception(e)
try: try:
@ -1126,7 +1126,7 @@ class TCPRelayHandler(object):
if self._local_sock: if self._local_sock:
logging.debug('destroying local') logging.debug('destroying local')
try: try:
self._loop.remove(self._local_sock) self._loop.removefd(self._local_sock_fd)
except Exception as e: except Exception as e:
shell.print_exception(e) shell.print_exception(e)
try: try:
@ -1403,7 +1403,7 @@ class TCPRelay(object):
logging.warn('unknown fd') logging.warn('unknown fd')
handle = True handle = True
try: try:
self._eventloop.remove(sock) self._eventloop.removefd(fd)
except Exception as e: except Exception as e:
shell.print_exception(e) shell.print_exception(e)
sock.close() sock.close()