Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing File Handles and Sockets in Winsock

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?

like image 326
Mikeage Avatar asked Dec 28 '08 12:12

Mikeage


1 Answers

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.

like image 146
Dave Ray Avatar answered Oct 19 '22 22:10

Dave Ray