reuse port

This commit is contained in:
j 2014-09-05 18:36:03 +02:00
parent 6cb3e13fb7
commit 0ef522f620
2 changed files with 4 additions and 0 deletions

View file

@ -149,6 +149,7 @@ def command_release(*args):
EXCLUDE=[ EXCLUDE=[
'--exclude', '.git', '--exclude', '.bzr', '--exclude', '.git', '--exclude', '.bzr',
'--exclude', 'pip_cache',
'--exclude', '.*.swp', '--exclude', '._*', '--exclude', '.DS_Store' '--exclude', '.*.swp', '--exclude', '._*', '--exclude', '.DS_Store'
] ]

View file

@ -162,6 +162,7 @@ class LocalNodes4(LocalNodesBase):
def send(self): def send(self):
packet = self.get_packet() packet = self.get_packet()
if packet: if packet:
logger.debug('send4 %s', packet)
sockaddr = (self._BROADCAST, self._PORT) sockaddr = (self._BROADCAST, self._PORT)
s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt (socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, self._TTL) s.setsockopt (socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, self._TTL)
@ -174,6 +175,7 @@ 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)
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
@ -206,6 +208,7 @@ 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)
group_bin = socket.inet_pton(socket.AF_INET6, self._BROADCAST) + '\0'*4 group_bin = socket.inet_pton(socket.AF_INET6, self._BROADCAST) + '\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