You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
socket.socket.getsockname() has inconsistent UNIX/Windows behavior #45390
The behavior and return value for calling socket.socket.getsockname() on
an unconnected unbound socket is unspecified. On UNIX, it returns an
address ('0.0.0.0', 0), while on Windows it raises an obscure exception
"error: (10022, 'Invalid argument')". This should be regularized; I'd
suggest returning None if there is no name (address) for the socket.
I think it is neither possible nor "good" to produce a uniform result.
Python traditionally exposes APIs "as-is", providing the system actually
has an API with the same name. It never tries to hide differing system
behaviors in the Python wrapper; if systems vary and it is desirable to
provide a uniform API, a different API is added.
However, it is also not possible to make that uniform, as getsockname(3)
gives an unspecified result, so it is not possible for Python to
actually determine whether there was a meaningful result.
The getsockname() function returns the value 0 if successful; otherwise
the value -1 is returned and the global variable errno is set to
indicate the error.
Activity
janssen commentedon Aug 28, 2007
The behavior and return value for calling socket.socket.getsockname() on
an unconnected unbound socket is unspecified. On UNIX, it returns an
address ('0.0.0.0', 0), while on Windows it raises an obscure exception
"error: (10022, 'Invalid argument')". This should be regularized; I'd
suggest returning None if there is no name (address) for the socket.
loewis commentedon Aug 29, 2007
I think it is neither possible nor "good" to produce a uniform result.
Python traditionally exposes APIs "as-is", providing the system actually
has an API with the same name. It never tries to hide differing system
behaviors in the Python wrapper; if systems vary and it is desirable to
provide a uniform API, a different API is added.
However, it is also not possible to make that uniform, as getsockname(3)
gives an unspecified result, so it is not possible for Python to
actually determine whether there was a meaningful result.
Closing as rejected.
janssen commentedon Apr 9, 2008
Here's what the OS X man page says:
The getsockname() function returns the value 0 if successful; otherwise
the value -1 is returned and the global variable errno is set to
indicate the error.