-
Notifications
You must be signed in to change notification settings - Fork 252
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
Replace ioctl with fcntl, fix ioctlsocket calls (64-bit fix) #356
Conversation
I would rewrite socket initialization as #ifdef WIN32
dedicated_listen_socket = socket(AF_INET, SOCK_STREAM, 0);
// ...
unsigned long arg = 1;
ioctlsocket(dedicated_listen_socket, FIONBIO, &arg);
#else // WIN32
#ifndef SOCK_NONBLOCK
#include <fcntl.h>
#define SOCK_NONBLOCK O_NONBLOCK
#endif
dedicated_listen_socket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
#endif And you don't have to use additional |
817b4d9
to
212d114
Compare
@winterheart Not all of these are socket initializations. As such, I consolidated the code into a single function in |
@@ -343,6 +346,10 @@ typedef struct { | |||
extern BOOL DP_active; | |||
extern BOOL TCP_active; | |||
extern BOOL IPX_active; | |||
|
|||
// create a new non-blocking socket | |||
int make_nonblocking(SOCKET sock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be called something like nw_SocketSetNonblock()
to match the rest of the functions defined here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was considered but it's used on other sockets as well where the nw_*
scheme wouldn't be appropriate.
`ioctl` and `ioctlsocket` take two different types of arguments but worked in the past due to long being 32-bit. However, ioctl functionality is non-standard and should not be used in code written after **1997** in order to make sockets non-blocking. This functionality was standardized as part of fcntl. * Using the new function `make_nonblocking` to make socket nonblocking
Would someone please merge this? It's been reviewed by two people already. |
PR has regression on Linux, see #398. |
These take two different types of arguments but worked in the past due to long being 32-bit.
Pull Request Type
Description
The
ioctl
argument for UNIX systems isint*
while theioctlsocket
argument for Windows isunsigned long*
. On 32-bit systems theses coincided so no problems but not on 64-bit. However, the behavior ofioctl
calls is non-standard which is why code should usefnctl
.See also:
Checklist
Additional Comments