Fixed SO_REUSEPORT not supported by Linux <3.9
Change-Id: If2dec4555dc436c1b16d7298c6f37d99e0e48cea Closes-Bug: 1451691
This commit is contained in:
parent
50936be342
commit
c09a295c40
@ -247,8 +247,14 @@ def bind_tcp(host, port, tcp_backlog):
|
||||
{'host': host, 'port': port})
|
||||
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
|
||||
# NOTE: Linux supports socket.SO_REUSEPORT only in 3.9 and later releases.
|
||||
try:
|
||||
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sock_tcp.setblocking(True)
|
||||
sock_tcp.bind((host, port))
|
||||
sock_tcp.listen(tcp_backlog)
|
||||
@ -262,7 +268,13 @@ def bind_udp(host, port):
|
||||
{'host': host, 'port': port})
|
||||
sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
|
||||
# NOTE: Linux supports socket.SO_REUSEPORT only in 3.9 and later releases.
|
||||
try:
|
||||
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
sock_udp.setblocking(True)
|
||||
sock_udp.bind((host, port))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user