|
@ -137,6 +137,7 @@ class UDPRelay(object): |
|
|
self._cache = lru_cache.LRUCache(timeout=timeout, |
|
|
self._cache = lru_cache.LRUCache(timeout=timeout, |
|
|
close_callback=self._close_client) |
|
|
close_callback=self._close_client) |
|
|
self._client_fd_to_server_addr = lru_cache.LRUCache(timeout=timeout) |
|
|
self._client_fd_to_server_addr = lru_cache.LRUCache(timeout=timeout) |
|
|
|
|
|
self._closed = False |
|
|
|
|
|
|
|
|
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0, |
|
|
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0, |
|
|
socket.SOCK_DGRAM, socket.SOL_UDP) |
|
|
socket.SOCK_DGRAM, socket.SOL_UDP) |
|
@ -251,7 +252,7 @@ class UDPRelay(object): |
|
|
self._eventloop = eventloop.EventLoop() |
|
|
self._eventloop = eventloop.EventLoop() |
|
|
self._eventloop.add(server_socket, eventloop.POLL_IN) |
|
|
self._eventloop.add(server_socket, eventloop.POLL_IN) |
|
|
last_time = time.time() |
|
|
last_time = time.time() |
|
|
while True: |
|
|
while not self._closed: |
|
|
try: |
|
|
try: |
|
|
events = self._eventloop.poll(10) |
|
|
events = self._eventloop.poll(10) |
|
|
except (OSError, IOError) as e: |
|
|
except (OSError, IOError) as e: |
|
@ -274,11 +275,17 @@ class UDPRelay(object): |
|
|
last_time = now |
|
|
last_time = now |
|
|
|
|
|
|
|
|
def start(self): |
|
|
def start(self): |
|
|
|
|
|
if self._closed: |
|
|
|
|
|
raise Exception('closed') |
|
|
t = threading.Thread(target=self._run) |
|
|
t = threading.Thread(target=self._run) |
|
|
t.setName('UDPThread') |
|
|
t.setName('UDPThread') |
|
|
t.setDaemon(False) |
|
|
t.setDaemon(False) |
|
|
t.start() |
|
|
t.start() |
|
|
self._thread = t |
|
|
self._thread = t |
|
|
|
|
|
|
|
|
|
|
|
def close(self): |
|
|
|
|
|
self._closed = True |
|
|
|
|
|
self._server_socket.close() |
|
|
|
|
|
|
|
|
def thread(self): |
|
|
def thread(self): |
|
|
return self._thread |
|
|
return self._thread |
|
|