mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[Patch #982681] Apply this patch correctly; makes set_reuse_addr() work on Windows
This commit is contained in:
parent
7323f08422
commit
5336f8caa4
1 changed files with 9 additions and 3 deletions
|
@ -263,14 +263,20 @@ class dispatcher:
|
||||||
def set_reuse_addr(self):
|
def set_reuse_addr(self):
|
||||||
# try to re-use a server port if possible
|
# try to re-use a server port if possible
|
||||||
try:
|
try:
|
||||||
|
# Windows SO_REUSEADDR is very broken (from a unixy perspective)
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
reuse_constant = socket.SO_EXCLUSIVEADDRUSE
|
||||||
|
else:
|
||||||
|
reuse_constant = socket.SO_REUSEADDR
|
||||||
|
|
||||||
self.socket.setsockopt(
|
self.socket.setsockopt(
|
||||||
socket.SOL_SOCKET, socket.SO_REUSEADDR,
|
socket.SOL_SOCKET, reuse_constant,
|
||||||
self.socket.getsockopt(socket.SOL_SOCKET,
|
self.socket.getsockopt(socket.SOL_SOCKET,
|
||||||
socket.SO_REUSEADDR) | 1
|
reuse_constant) | 1
|
||||||
)
|
)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# ==================================================
|
# ==================================================
|
||||||
# predicates for select()
|
# predicates for select()
|
||||||
# these are used as filters for the lists of sockets
|
# these are used as filters for the lists of sockets
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue