[issue22018] Add a new signal.set_wakeup_socket() function
STINNER Victor
report at bugs.python.org
Thu Jul 24 17:51:26 CEST 2014
STINNER Victor added the comment:
> 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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22018>
_______________________________________
More information about the Python-bugs-list
mailing list