Question

I'm porting some code from BSD sockets to Winsock, and I'm not sure how to handle the case below.

My original application runs a select on both stdin and the network socket:

FD_SET(sock, &fd);
FD_SET(0, &fd);
...
if (select(..., &fd, ... )...)

Trying to run this in Winsock gives an error 10038 (WSAENOTSOCK), which makes sense, since what was file handle 0 in Linux (stdin) is not a socket (more precisely: a SOCKET type) in Windows.

Is there an easy way to port this test to Windows sockets?

Was it helpful?

Solution

Winsock's select() only works with sockets. A more 'Windows-y' alternative would be to use Asynchronous I/O on both handles and then WaitForMultipleObjects.

OTHER TIPS

I'd love to be corrected, but as far as I know, Winsock does not extend beyond the realm of sockets. That is, Unix's "everything is a file" philosophy for the select(), read(), write(), etc system calls is not there in Winsock.

I'm sure you can do something similar with just the Win32 API working on socket and console handles, but it's not going to look much like Winsock (or BSD) anymore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top