This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author georg.brandl
Recipients docs@python, georg.brandl
Date 2013-10-12.16:33:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <52597A2F.60807@python.org>
In-reply-to <1984648.JD0MPFlghQ@noisy.pr41.sk>
Content
-------- Original-Nachricht --------
Betreff: [docs] socket.fileno() documentation
Datum: Thu, 10 Oct 2013 19:27:35 +0200
Von: Vlado Potisk <vlado@poti.sk>
An: docs@python.org

I might be wrong but in my opinion the socket library documentation is not
clear enough regarding the behaviour of the fileno() method in a case of a
failure.

In the Python 3.2 socket library documentation there is:
----
exception socket.error

    A subclass of IOError, this exception is raised for socket-related errors.
-----
 socket.close()

    Close the socket. All future operations on the socket object will fail.
----
 socket.fileno()

    Return the socket’s file descriptor (a small integer).
----

Based on the information quoted above, I wrote a test if a socket is active or
if it has been closed already:

try:
	sock.fileno()
except socket.error:
	return False
return True

But is doesn't work. I have found out that fileno() returns -1 on a closed
socket. Replacing fileno() with e.g. getsockname() fixes the code.

It looks like a fileno's failure - unlike to getsockname's failure - is not
expressed by raising an exception, but by returning -1. However this seems to
be not documented and that's why I'm unsure if I may rely on this.
History
Date User Action Args
2013-10-12 16:33:57georg.brandlsetrecipients: + georg.brandl, docs@python
2013-10-12 16:33:57georg.brandllinkissue19234 messages
2013-10-12 16:33:57georg.brandlcreate