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 vstinner
Recipients gvanrossum, loewis, neologix, pitrou, python-dev, vstinner, yselivanov
Date 2014-07-24.15:51:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406217086.61.0.209948286054.issue22018@psf.upfronthosting.co.za>
In-reply-to
Content
> That's not what I'm answering to, though. See option B above.
> Again, what's wrong with passing the socket as a fileno?

There is nothing "wrong", it's just that I prefer option (C) over the option (B).

Quick poll in the Python stdlib for functions accepting sockets on Windows.

Expect a socket object:

- asyncore.dispatcher.set_socket()
- ssl.wrap_socket(), ssl.SSLSocket()

Expect a (socket) handle:

- os.set_handle_inheritable(), function accepting any kind of handle, not only socket handles

Accept a file descriptor or an object with a fileno() method:

- select.select(), select.poll()

Hum, I'm not convinced by the poll :-/ There are too few functions to use it to take a decision.


On UNIX, sockets are just file descriptors, like any other file descriptor. So all functions accepting file descriptors accept sockets.

--

Note: select.select() uses "int PyObject_AsFileDescriptor(PyObject *o)" to get the socket handle of a socket, I would expect the SOCKET_T type here. Does it mean that socket handle fits in a C int? Yes according to this article:

http://stackoverflow.com/questions/1953639/is-it-safe-to-cast-socket-to-int-under-win64

"Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because the value constitutes an index in per-process table of limited size and not a real pointer."

"The per-process limit on kernel handles is 2^24."

I wrote a stress test creating and closing sockets in a loop. I ran the test on Windows 7 64 bit with 1 GB of memory. The maximum seen socket handle is 1,330,836 after creating 5,613,807 sockets (with a list of 331,343 open socekts), it's much smaller than 2^32.

OpenSSL stores socket handles in C int.
History
Date User Action Args
2014-07-24 15:51:26vstinnersetrecipients: + vstinner, gvanrossum, loewis, pitrou, neologix, python-dev, yselivanov
2014-07-24 15:51:26vstinnersetmessageid: <1406217086.61.0.209948286054.issue22018@psf.upfronthosting.co.za>
2014-07-24 15:51:26vstinnerlinkissue22018 messages
2014-07-24 15:51:25vstinnercreate