With a small test program (compiled with mingw on Linux), I noticed that one cannot use the read
and write
calls on the socket fd as obtained using Winsock2's implementation of the socket
call. The write call returns <0 and sets errno=EBADF.
Think of programs run from xinetd, minus their assumption that their stdin/stdout always is a socket. (Some programs do call getpeername for example, which will fail if it is not a socket, subsequently they may exit prematurely.)
So how are {file descriptor type}-agnostic programs that just read/write from/to stdin/stdout supposed to reasonably work in the win32 environment unless making assumptions about the fd?
Or more simply put, is there some magic function call to be executed to wire up Winsock2 socket fds with the win32 (well, mingw) write
implementation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…