Browse Source

catch bind error

dev
破娃酱 8 years ago
parent
commit
ce25bbf650
  1. 3
      shadowsocks/tcprelay.py
  2. 5
      shadowsocks/udprelay.py

3
shadowsocks/tcprelay.py

@ -548,7 +548,10 @@ class TCPRelayHandler(object):
local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP)
if local_addrs[0][0] == af: if local_addrs[0][0] == af:
logging.debug("bind %s" % (bind_addr,)) logging.debug("bind %s" % (bind_addr,))
try:
sock.bind((bind_addr, 0)) sock.bind((bind_addr, 0))
except Exception as e:
logging.warn("bind %s fail" % (bind_addr,))
def _create_remote_socket(self, ip, port): def _create_remote_socket(self, ip, port):
if self._remote_udp: if self._remote_udp:

5
shadowsocks/udprelay.py

@ -1025,10 +1025,13 @@ class UDPRelay(object):
if bind_addr in self._ignore_bind_list: if bind_addr in self._ignore_bind_list:
bind_addr = None bind_addr = None
if bind_addr: if bind_addr:
local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_DGRAM, socket.SOL_UDP)
if local_addrs[0][0] == af: if local_addrs[0][0] == af:
logging.debug("bind %s" % (bind_addr,)) logging.debug("bind %s" % (bind_addr,))
try:
sock.bind((bind_addr, 0)) sock.bind((bind_addr, 0))
except Exception as e:
logging.warn("bind %s fail" % (bind_addr,))
def _handle_server(self): def _handle_server(self):
server = self._server_socket server = self._server_socket

Loading…
Cancel
Save