diff options
author | Gregory P. Smith <greg@krypto.org> | 2013-11-17 22:19:32 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2013-11-17 22:19:32 (GMT) |
commit | 162307fa3558341b82570a42b2f023b9623df822 (patch) | |
tree | 102e850a479efe08715d76d3c2b7f5de6b04448f /Lib/test/support | |
parent | 7929a1da1a6d18894210ff82f6107e51d7566bb0 (diff) | |
download | cpython-162307fa3558341b82570a42b2f023b9623df822.zip cpython-162307fa3558341b82570a42b2f023b9623df822.tar.gz cpython-162307fa3558341b82570a42b2f023b9623df822.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/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index dbd7846..233b13a 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -570,9 +570,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) |