use getaddrinfo to know if we should use ipv4 or v6 for zeroconf
This commit is contained in:
parent
7dbef236af
commit
da966efaa7
|
@ -59,16 +59,15 @@ class ZeroconfListener(IdleObject):
|
||||||
self.conn_holder = conn_holder
|
self.conn_holder = conn_holder
|
||||||
|
|
||||||
def bind(self):
|
def bind(self):
|
||||||
try:
|
ai = socket.getaddrinfo(None, self.port, socket.AF_UNSPEC,
|
||||||
self._serv = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
socket.SOCK_STREAM, 0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG)[0]
|
||||||
except socket.error:
|
self._serv = socket.socket(ai[0], ai[1])
|
||||||
self._serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
self._serv.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||||
self._serv.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
self._serv.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||||
# will fail when port is busy, or we don't have rights to bind
|
# will fail when port is busy, or we don't have rights to bind
|
||||||
try:
|
try:
|
||||||
self._serv.bind(('', self.port))
|
self._serv.bind((ai[4][0], self.port))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
# unable to bind, show error dialog
|
# unable to bind, show error dialog
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue