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

Fix two small issues that cause Windows problems #21

Closed
wants to merge 2 commits into from

Conversation

borrrden
Copy link
Contributor

This is also included in #17 but I figured I'd make it standalone as well since it is outside the context of TLS support.

1. The return value of `accept` for Windows is not -1 on failure, but `INVALID_SOCKET` (which is unsigned).  Failures were getting reported as error code 0.
2. If the first argument to `accept` is `NULL` then the second is also required to be
@fpagliughi
Copy link
Owner

Yes. Cool. Better to consider some loosely-related fixes separately than in one big PR.

OMG, is the Windows SOCKET type unsigned?!?!
If so, can the accept() call really be the only place in the code that this is a problem?

@borrrden
Copy link
Contributor Author

Good thinking, there are probably more. I'll update the PR to fix the rest :p

As the previous commit, the `::socket` function returns `SOCKET` (unsigned) on Windows.  All other areas that use `check_ret` have been confirmed to return -1 on error on Windows as well (in general, Winsock2 functions that return int return SOCKET_ERROR (-1) on failure)
@borrrden
Copy link
Contributor Author

I counted roughly a dozen places that check_ret or check_ret_bool was used (all I could find). There was only one other function that returns SOCKET on Windows so I corrected it.

@fpagliughi
Copy link
Owner

Cool. I'll merge this shortly and take a look. I also grep'ed for any additional "< 0" comparisons, but I think we're close. I may have been aware of this when I first wrote the library, but forgotten it since then! There are a lot of explicit comparisons to the invalid socket constant, which I don't normally do in Linux programming. I used Windows a lot back then, but not really at all any more.

@fpagliughi
Copy link
Owner

I made one minor change... As check_socket() and check_socket_bool() are specifically meant to take sockets, I changed them from template functions to regular inline functions taking a socket_t value.

Pushed into develop.

@fpagliughi fpagliughi closed this Aug 31, 2019
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.

2 participants