Is it possible to set timeout to accept function when using blocking winsockets? Like we can do to recv and send function via setsockopt?
Seems like it’s not possible, but I want to ensure.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Select function can be used with timeout. Though, select is most commonly used with non-blocking sockets, I haven’t read anything that prevents passing a blocking socket to select. If the select function times out, then you have the behavior equivalent of accept timeout.
From MSDN
“The parameter readfds identifies the sockets that are to be checked for readability. If the socket is currently in the listen state, it will be marked as readable if an incoming connection request has been received such that an accept is guaranteed to complete without blocking. For other sockets, readability means that queued data is available for reading such that a call to recv, WSARecv, WSARecvFrom, or recvfrom is guaranteed not to block.”
This should give you the behaviour you are expecting.