Advertisement

nonblocking socket (winsock)

Started by November 19, 2002 01:53 PM
8 comments, last by Leadorn 22 years, 2 months ago
Hi Ive been searching the msdn for a long time and cant find information about setting a socket to nonblocking.
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.
Advertisement
so if I want to make socket s nonblocket I use this line?

WSAEventSelect(s,0,0);
?
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.
try

unsigned long argp = 1;
ioctlsocket(s, FIONBIO, &argp);
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.
Advertisement
use WSAGetLastError() to determine the exact error for the send() and recv() calls.
WSAGetLastError(); can I use this after every recv call? Is it slow?
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?
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
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement