Fix test.support.bind_port() to not cause an error when Python was compiled

on a system with SO_REUSEPORT defined in the headers but run on a system
with an OS kernel that does not support that reasonably new socket option.
This commit is contained in:
Gregory P. Smith 2013-11-17 22:21:02 +00:00
commit b6e622d184
2 changed files with 13 additions and 3 deletions

View File

@ -594,9 +594,15 @@ def bind_port(sock, host=HOST):
raise TestFailed("tests should never set the SO_REUSEADDR " \
"socket option on TCP/IP sockets!")
if hasattr(socket, 'SO_REUSEPORT'):
if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
raise TestFailed("tests should never set the SO_REUSEPORT " \
"socket option on TCP/IP sockets!")
try:
if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
raise TestFailed("tests should never set the SO_REUSEPORT " \
"socket option on TCP/IP sockets!")
except OSError:
# Python's socket module was compiled using modern headers
# thus defining SO_REUSEPORT but this process is running
# under an older kernel that does not support SO_REUSEPORT.
pass
if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)

View File

@ -50,6 +50,10 @@ Core and Builtins
Library
-------
- Fix test.support.bind_port() to not cause an error when Python was compiled
on a system with SO_REUSEPORT defined in the headers but run on a system
with an OS kernel that does not support that reasonably new socket option.
- Fix compilation error under gcc of the ctypes module bundled libffi for arm.
- Issue #19448: Add private API to SSL module to lookup ASN.1 objects by OID,