Fix #1209
This commit is contained in:
parent
e332ec93e9
commit
b3dbcd4b32
1 changed files with 14 additions and 0 deletions
|
@ -18,6 +18,8 @@
|
||||||
from __future__ import absolute_import, division, print_function, \
|
from __future__ import absolute_import, division, print_function, \
|
||||||
with_statement
|
with_statement
|
||||||
|
|
||||||
|
import os
|
||||||
|
import atexit
|
||||||
import errno
|
import errno
|
||||||
import traceback
|
import traceback
|
||||||
import socket
|
import socket
|
||||||
|
@ -35,6 +37,9 @@ STAT_SEND_LIMIT = 50
|
||||||
class Manager(object):
|
class Manager(object):
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
atexit.register(self.cleanup)
|
||||||
|
self._is_unix = False
|
||||||
|
self._mngr_address = None
|
||||||
self._config = config
|
self._config = config
|
||||||
self._relays = {} # (tcprelay, udprelay)
|
self._relays = {} # (tcprelay, udprelay)
|
||||||
self._loop = eventloop.EventLoop()
|
self._loop = eventloop.EventLoop()
|
||||||
|
@ -57,6 +62,8 @@ class Manager(object):
|
||||||
else:
|
else:
|
||||||
addr = manager_address
|
addr = manager_address
|
||||||
family = socket.AF_UNIX
|
family = socket.AF_UNIX
|
||||||
|
self._is_unix = True
|
||||||
|
self._mngr_address = manager_address
|
||||||
self._control_socket = socket.socket(family,
|
self._control_socket = socket.socket(family,
|
||||||
socket.SOCK_DGRAM)
|
socket.SOCK_DGRAM)
|
||||||
self._control_socket.bind(addr)
|
self._control_socket.bind(addr)
|
||||||
|
@ -78,6 +85,13 @@ class Manager(object):
|
||||||
a_config['password'] = password
|
a_config['password'] = password
|
||||||
self.add_port(a_config)
|
self.add_port(a_config)
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
if self._is_unix:
|
||||||
|
try:
|
||||||
|
os.unlink(self._mngr_address)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def add_port(self, config):
|
def add_port(self, config):
|
||||||
port = int(config['server_port'])
|
port = int(config['server_port'])
|
||||||
servers = self._relays.get(port, None)
|
servers = self._relays.get(port, None)
|
||||||
|
|
Loading…
Add table
Reference in a new issue