Browse Source

handle signal soon; #179

auth
clowwindy 10 years ago
parent
commit
380a646f09
  1. 5
      shadowsocks/eventloop.py
  2. 16
      shadowsocks/tcprelay.py
  3. 10
      shadowsocks/udprelay.py

5
shadowsocks/eventloop.py

@ -206,9 +206,10 @@ class EventLoop(object):
events = self.poll(1) events = self.poll(1)
except (OSError, IOError) as e: except (OSError, IOError) as e:
if errno_from_exception(e) in (errno.EPIPE, errno.EINTR): if errno_from_exception(e) in (errno.EPIPE, errno.EINTR):
# Happens when the client closes the connection # EPIPE: Happens when the client closes the connection
# EINTR: Happens when received a signal
# handles them as soon as possible
logging.debug('poll:%s', e) logging.debug('poll:%s', e)
continue
else: else:
logging.error('poll:%s', e) logging.error('poll:%s', e)
import traceback import traceback

16
shadowsocks/tcprelay.py

@ -632,14 +632,14 @@ class TCPRelay(object):
if now - self._last_time > TIMEOUT_PRECISION: if now - self._last_time > TIMEOUT_PRECISION:
self._sweep_timeout() self._sweep_timeout()
self._last_time = now self._last_time = now
if self._closed: if self._closed:
if self._server_socket: if self._server_socket:
self._eventloop.remove(self._server_socket) self._eventloop.remove(self._server_socket)
self._server_socket.close() self._server_socket.close()
self._server_socket = None self._server_socket = None
logging.info('closed listen port %d', self._listen_port) logging.info('closed listen port %d', self._listen_port)
if not self._fd_to_handlers: if not self._fd_to_handlers:
self._eventloop.remove_handler(self._handle_events) self._eventloop.remove_handler(self._handle_events)
def close(self, next_tick=False): def close(self, next_tick=False):
self._closed = True self._closed = True

10
shadowsocks/udprelay.py

@ -264,11 +264,11 @@ class UDPRelay(object):
self._cache.sweep() self._cache.sweep()
self._client_fd_to_server_addr.sweep() self._client_fd_to_server_addr.sweep()
self._last_time = now self._last_time = now
if self._closed: if self._closed:
self._server_socket.close() self._server_socket.close()
for sock in self._sockets: for sock in self._sockets:
sock.close() sock.close()
self._eventloop.remove_handler(self._handle_events) self._eventloop.remove_handler(self._handle_events)
def close(self, next_tick=False): def close(self, next_tick=False):
self._closed = True self._closed = True

Loading…
Cancel
Save