我正在做一些相当简单的跨平台TCP套接字编程.遗憾的是,我发现在 Windows上编译时,我的套接字默认是非阻塞的,而在OS X上,它们默认是阻塞的.如何在Windows上强制套接字进入阻止模式?它们
我的代码部分基于以下简单示例:
http://cs.baylor.edu/~donahoo/practical/CSockets/code/TCPEchoClient.c
http://cs.baylor.edu/~donahoo/practical/CSockets/code/TCPEchoServer.c
Although blocking operations on
sockets are supported under Windows
Sockets, their use is strongly
discouraged. Programmers who are
constrained to use blocking mode —
for example, as part of an existing
application which is to be ported —
should be aware of the semantics of
blocking operations in Windows
Sockets.
如果您完全了解here中列出的众多问题,并且发现处理所有这些问题比设计您的程序更适合Windows而不是Unix中的半端口,请直接拨打ioctlsocket电话与cmd参数设置为FIONBIO,第三个参数指向值为0的长字.但是,不要说你没有被警告;-).