summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2013-11-17 22:21:02 (GMT)
committerGregory P. Smith <greg@krypto.org>2013-11-17 22:21:02 (GMT)
commitb6e622d184604771088b5d2dd4f4cf0cddb2a3ae (patch)
tree98126d5e495981274e9bd8b25e5f0a1cf69967cd /Lib
parent61b976f12714fe6dbea5d9da52e2c814f4a0522a (diff)
parent162307fa3558341b82570a42b2f023b9623df822 (diff)
downloadcpython-b6e622d184604771088b5d2dd4f4cf0cddb2a3ae.zip
cpython-b6e622d184604771088b5d2dd4f4cf0cddb2a3ae.tar.gz
cpython-b6e622d184604771088b5d2dd4f4cf0cddb2a3ae.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support/__init__.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 20a5e85..b6a430e 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -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)