(1)套接字工作在非阻塞模式,设置接受超时
1
2
3
4
5
6
7
8
9
|
// 创建套接字
SOCKET sock = WSASocket(AF_INET, SOCK_STREAM, IPPOROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
if
(INVALID_SOCKET == sock)
{
printf
(
"WSASocket call failed. Error code: %d"
, WSAGetLastError());
}
//
int
nTimeout = 5*1000;
//设置超时5秒
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (
char
*)&nTimeout,
sizeof
(nTimeout));
|