Roselyn Verbo Domingo
Roselyn Verbo Domingo

Reputation: 506

recv(MSG_PEEK) timeout

I have a socket where I set a timeout for recv(). I have two steps for recv(), first I check content of received data if complete using MSG_PEEK | MSG_DONTWAIT.

recvTimeout.tv_sec = mRecvTimeoutSecs;
recvTimeout.tv_usec = mRecvTimeoutUSecs; 
sendTimeout.tv_sec = mSendTimeoutSecs;
sendTimeout.tv_usec = mSendTimeoutUSecs;

result = enableSocketOption(SOL_SOCKET, SO_RCVTIMEO, &recvTimeout, sizeof(recvTimeout));

peekdLen = ::recv(mSocket, peekDataBuffer, MAX_RECV_LENGTH, MSG_PEEK | MSG_DONTWAIT);

I'm just thinking if recv() will timeout if I used MSG_PEEK | MSG_DONTWAIT.

Upvotes: 1

Views: 1119

Answers (1)

the swine
the swine

Reputation: 11031

No, the socket will not timeout, as MSG_DONTWAIT will cause recv() to return immediately. Note that if you set like 1 msec timeout, then it might timeout - that would depend on the implementation (on which OS your code runs on).

Upvotes: 1

Related Questions