dont fail if socket.SO_REUSEPORT is not defined
This commit is contained in:
parent
9155343c5b
commit
59062d40c7
1 changed files with 4 additions and 2 deletions
|
@ -174,7 +174,8 @@ class LocalNodes4(LocalNodesBase):
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
if hasattr(socket, 'SO_REUSEPORT'):
|
||||||
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||||
mreq = struct.pack("=4sl", socket.inet_aton(self._BROADCAST), socket.INADDR_ANY)
|
mreq = struct.pack("=4sl", socket.inet_aton(self._BROADCAST), socket.INADDR_ANY)
|
||||||
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
|
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
|
||||||
self._socket = s
|
self._socket = s
|
||||||
|
@ -207,7 +208,8 @@ class LocalNodes6(LocalNodesBase):
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
if hasattr(socket, 'SO_REUSEPORT'):
|
||||||
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||||
group_bin = socket.inet_pton(socket.AF_INET6, self._BROADCAST) + b'\0'*4
|
group_bin = socket.inet_pton(socket.AF_INET6, self._BROADCAST) + b'\0'*4
|
||||||
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group_bin)
|
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group_bin)
|
||||||
self._socket = s
|
self._socket = s
|
||||||
|
|
Loading…
Reference in a new issue