Archived

This topic is now archived and is closed to further replies.

nonblocking socket (winsock)

This topic is 5504 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You can use ioctlsocket() with an FIONBIO arguement to set a socket to non blocking. Also with Winsock a call to WSAAsyncSelect() or WSAEventSelect() will set a socket to non-blocking mode.

Share this post


Link to post
Share on other sites
how about using

ioctlsocket(sIncomingConnection,FIONBIO,1);

I dont understand what the parameter 3 is for. Msdn say that it should be a non zero when FIONBIO is to be used. But what should I but there. I just want to set socket s to nonblocking.

Share this post


Link to post
Share on other sites
This seems to work, but there is one problem. Recv and send return -1 (SOCKET_ERROR) so how do i know if the clientprogram just closed down the program without disconnecting.

If clientprogram disconnect i get 0 in return from recv and send.

Share this post


Link to post
Share on other sites
I assigned my listensocket to nonblocking with
unsigned long argp = 1;
ioctlsocket(s, FIONBIO, &argp);


but now all my new sockets are also nonblocking without me using
unsigned long argp = 1;
ioctlsocket(s, FIONBIO, &argp);

How is this possible?

Share this post


Link to post
Share on other sites
Sounds like the new sockets are inheriting the "parent" socket''s settings. It should be possible to just unset the non-blocking flag by executing ioctlsocket() with argp set to 0.

cu,
Prefect

Share this post


Link to post
Share on other sites