Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use poll(2) for timeouts on socket #176

Merged
merged 1 commit into from Apr 15, 2014
Merged

Use poll(2) for timeouts on socket #176

merged 1 commit into from Apr 15, 2014

Conversation

alanxz
Copy link
Owner

@alanxz alanxz commented Mar 14, 2014

Use poll(2) instead of select(2) to do timeout operations on sockets. This helps
with the situation where the fd is larger than FD_MAXSIZE.

Fixes #168

@abogosyan
Copy link

Will it work on Windows?

@alanxz
Copy link
Owner Author

alanxz commented Mar 14, 2014

Not yet... (which is why this isn't in the master branch yet).

winsock2 has a poll implementation, however its only available in Vista/Server 2008 and later. I need to consider whether to support Win32 clients older than Vista, and consider providing an alternate implementation for those systems that don't support it.

@mclassen
Copy link

mclassen commented Apr 8, 2014

For Windows, you can actually just define FD_SETSIZE to a larger value, which works. On Linux it doesn't work that way, so you need poll() there (or something equivalent).

I would suggest simply using #ifdefs to use poll() for non-windows systems and set FD_SETSIZE to a larger value for Windows. (I did that in my workaround)

@alanxz
Copy link
Owner Author

alanxz commented Apr 10, 2014

I'm trying to avoid having a lot of #ifdefs if possible as it makes it more difficult to understand what is going on in the code and makes making changes to the code a more treacherous chore. Your workaround does work consistently on Win32 though.

@abogosyan
Copy link

The problem is not only FD_SETSIZE, as I described here: #168 (comment) in Linux you could stuck at recv function if nothing to receive and EINTR happened.

I'd suggest to have OS-specific functions here...

Use poll(2) instead of select(2) to do timeout operations on sockets. This helps
with the situation where the fd is larger than FD_MAXSIZE.

Fixes #168
@alanxz alanxz merged commit a78aa8a into master Apr 15, 2014
@alanxz alanxz deleted the poll_timeout branch July 11, 2014 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch socket timeout logic to use poll() instead of select()
3 participants