On Sun, 13 Mar 2005 19:21, Dmitry Timoshkov wrote:
"Eric Pouech" pouech-eric@wanadoo.fr wrote:
For asynchronous read operations, hFile can be any handle opened with the FILE_FLAG_OVERLAPPED flag by the CreateFile function, or a socket handle returned by the socket or accept function.
which means that ReadFile() only works on socket for async reads, not sync reads. I'll precise this.
It's not quite correct. The following sequence of code will cause all sockets created subsequently with socket() to be usable with ReadFile() and WriteFile() without overlapped calls. I can confirm that I've done this many times (using sockets of this variety is a good way of porting UNIX apps which use select on a pipe).
int optval = SO_SYNCHRONOUS_NONALERT;
setsockopt( INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &optval, sizeof optval );
According to MSDN you can also use WSASocket in Windows Sockets version 2.0 or later to create sockets that do this by not using the WSA_FLAG_OVERLAPPED flag.