Discussion:
How to set a socket to nonblocking?
(too old to reply)
Vincent
2003-10-24 19:02:31 UTC
Permalink
Dear All,

I am new on Windows Socket programming. It is esay to set a socket to
nonblocking in Unix environment. How to do it in Windows?

Thanks in advance.

Vincent
John Duddy
2003-10-24 20:15:57 UTC
Permalink
I think this will do it. I am not use if you also have to pass
WSA_FLAG_OVERLAPPED to WSASocket() when you create it.

unsigned long lNonBlocking = 1;
ioctlsocket(hSocket, FIONBIO, &lNonBlocking);
Post by Vincent
Dear All,
I am new on Windows Socket programming. It is esay to set a socket to
nonblocking in Unix environment. How to do it in Windows?
Thanks in advance.
Vincent
Vincent
2003-10-24 20:19:55 UTC
Permalink
Thanks. It works.

Vincent
Post by John Duddy
I think this will do it. I am not use if you also have to pass
WSA_FLAG_OVERLAPPED to WSASocket() when you create it.
unsigned long lNonBlocking = 1;
ioctlsocket(hSocket, FIONBIO, &lNonBlocking);
Post by Vincent
Dear All,
I am new on Windows Socket programming. It is esay to set a socket to
nonblocking in Unix environment. How to do it in Windows?
Thanks in advance.
Vincent
Arkady Frenkel
2003-10-25 20:39:59 UTC
Permalink
Are you sure that WSA_FLAG_OVERLAPPED change socket to non-blocked , AFAIK
only
WSAAsyncSelect()/WSAAsyncEvent() do that in windows.
Arkady
Post by John Duddy
I think this will do it. I am not use if you also have to pass
WSA_FLAG_OVERLAPPED to WSASocket() when you create it.
unsigned long lNonBlocking = 1;
ioctlsocket(hSocket, FIONBIO, &lNonBlocking);
Post by Vincent
Dear All,
I am new on Windows Socket programming. It is esay to set a socket to
nonblocking in Unix environment. How to do it in Windows?
Thanks in advance.
Vincent
Alun Jones [MS MVP]
2003-10-27 15:09:08 UTC
Permalink
Post by Arkady Frenkel
Are you sure that WSA_FLAG_OVERLAPPED change socket to non-blocked , AFAIK
only
WSAAsyncSelect()/WSAAsyncEvent() do that in windows.
WSA_FLAG_OVERLAPPED is required to be set, if you call WSASocket to create
your socket, to create a socket that _can_ become non-blocking. In fact, if
you create a socket without WSA_FLAG_OVERLAPPED, there are all sorts of
restrictions on what you can do with it - I'm not sure that it's ever worth
doing so.

However, once you've got a blocking socket that is capable of being made
non-blocking, you can make it non-blocking with any of the following
functions:
WSAAsyncSelect()
WSAEventSelect()
ioctlsocket(), with parameter FIONBIO.

Once a socket is non-blocking, if you want to make it blocking, you will
want to de-register any events or window messages associated with it (by
calling WSAEventSelect or WSAAsyncSelect as outlined in their
documentation), and then call ioctlsocket, with parameter FIONBIO.

[If that's confused anyone - remember that ioctlsocket() with parameter
FIONBIO can be called with one value to turn it on, and another to turn it
off. Go see the documentation for full details.]

Alun.
~~~~

[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Find us at http://www.wftpd.com or email
1602 Harvest Moon Place | ***@texis.com.
Cedar Park TX 78613-1419 | WFTPD, WFTPD Pro are Windows FTP servers.
Fax/Voice +1(512)258-9858 | Try our NEW client software, WFTPD Explorer.
Arkady Frenkel
2003-10-27 21:26:08 UTC
Permalink
That's was my point , I believe that WSAAsyncSelect/Even inside call old bsd
ioctlsocket() too because
and WSA_FLAG_OVERLAPPED not needed as berkeley sockets have no knowledge of
WSA
Arkady
Post by Alun Jones [MS MVP]
Post by Arkady Frenkel
Are you sure that WSA_FLAG_OVERLAPPED change socket to non-blocked , AFAIK
only
WSAAsyncSelect()/WSAAsyncEvent() do that in windows.
WSA_FLAG_OVERLAPPED is required to be set, if you call WSASocket to create
your socket, to create a socket that _can_ become non-blocking. In fact, if
you create a socket without WSA_FLAG_OVERLAPPED, there are all sorts of
restrictions on what you can do with it - I'm not sure that it's ever worth
doing so.
However, once you've got a blocking socket that is capable of being made
non-blocking, you can make it non-blocking with any of the following
WSAAsyncSelect()
WSAEventSelect()
ioctlsocket(), with parameter FIONBIO.
Once a socket is non-blocking, if you want to make it blocking, you will
want to de-register any events or window messages associated with it (by
calling WSAEventSelect or WSAAsyncSelect as outlined in their
documentation), and then call ioctlsocket, with parameter FIONBIO.
[If that's confused anyone - remember that ioctlsocket() with parameter
FIONBIO can be called with one value to turn it on, and another to turn it
off. Go see the documentation for full details.]
Alun.
~~~~
[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Find us at http://www.wftpd.com or email
Cedar Park TX 78613-1419 | WFTPD, WFTPD Pro are Windows FTP servers.
Fax/Voice +1(512)258-9858 | Try our NEW client software, WFTPD Explorer.
Alun Jones [MS MVP]
2003-10-28 15:55:43 UTC
Permalink
Post by Arkady Frenkel
That's was my point , I believe that WSAAsyncSelect/Even inside call old bsd
ioctlsocket() too because
and WSA_FLAG_OVERLAPPED not needed as berkeley sockets have no knowledge of
WSA
A call to socket(), the BSD socket creation function, will create a socket
that has the WSA_FLAG_OVERLAPPED flag applied to it. You cannot create a
non-overlapped socket using socket(). It is only when you call WSASocket()
that you must specify WSA_FLAG_OVERLAPPED if your socket is to become
non-blocking at a later stage.

If you stick with BSD socket calls, you won't have to worry about
WSA-anything, except for WSAStartup and WSACleanup.

Alun.
~~~~

[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Find us at http://www.wftpd.com or email
1602 Harvest Moon Place | ***@texis.com.
Cedar Park TX 78613-1419 | WFTPD, WFTPD Pro are Windows FTP servers.
Fax/Voice +1(512)258-9858 | Try our NEW client software, WFTPD Explorer.
Loading...