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 neologix, pitrou, vstinner
Date 2011-06-09.22:53:09
SpamBayes Score 1.6653345e-16
Marked as misclassified No
Message-id <1307659980.25903.23.camel@marge>
In-reply-to <BANLkTinr_0hANceEV8mUJCVLp6kU7GnqBA@mail.gmail.com>
Content
> So, this _PyCheckSelectable_fd ? function/macro would:
> - return true (1) on Visual Studio or if
> Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE is defined
> - return false (0) if the file descriptor is greater than FD_SETSIZE otherwise
> Do we agree on that?

Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE is specific to Windows.

/* WinSock does not use a bitmask in select, and uses
   socket handles greater than FD_SETSIZE */
#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE

I don't understand if socket file descriptors are different than
(classic) file descriptors.

socketmodule.c uses Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int), which
means that the socket type can be different (bigger) than int.

"#if defined(_MSC_VER)" is maybe redundant with
Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE (with "#ifdef MS_WINDOWS" ?).

Does other compilers, like Cygwin / MinGW, also use WinSock?

> Where should I add it? selectmodule, posixmodule, somewhere else?

_Py_Verify_fd() is defined in posixmodule.c and fileobject.h.

If you would like write a _PyCheckSelectable_fd() function/macro, it can
be defined in fileobject.h, and implemented anymore. selectmodule.c is
maybe a better choice than posixmodule.c because posixmodule.c doesn't
use select. Or maybe in socketmodule.c if you reuse IS_SELECTABLE code.

For the name, I would prefer _PyIsSelectable_fd(). With "check", I would
have to read the name to check if it should return 0 or non-zero if the
fd is selectable.

--

Instead of _PyCheckSelectable_fd(), we can maybe do even better: write a
function to check if a file descriptor is ready to read or write using
poll() (of select() if poll() is not available). Example:

int _Py_FDIsReady(int fd, int writing, double timeout);

Returns:
1: fd is ready to read, or to write if writing is set
0: fd is not ready
-1: error, check errno (or maybe raise a Python error?
internal_select_ex() in socketmodule.c doesn't raise an exception)

("_Py_FDIsReady" name is horrible, but I don't have a better suggestion
yet)

poll() accepts negative timeout, whereas select() doesn't, and so
_PyCheckSelectable_fd() should raise an error if timeout is negative to
be portable.

I propose to use poll() rather than select() because I suppose that it a
little bit faster (maybe only if the fd number is big? e.g. fd=1023) The
difference to wait a single file descriptor is maybe nul.

What should be done in case of EINTR? PyThread_acquire_lock_timed() has
an intr_flag parameter to decide.

I don't think that "int fd" works with SOCKET_T (socket module), which
can be bigger than an int.

Well, _PyCheckSelectable_fd() is much more complex to implement than the
initial suggestion...
History
Date User Action Args
2011-06-09 22:53:10vstinnersetrecipients: + vstinner, pitrou, neologix
2011-06-09 22:53:10vstinnerlinkissue12287 messages
2011-06-09 22:53:09vstinnercreate