The recv () window ratio takes infinite time - how's the timeout?

I use file descriptors to find readable sockets and keep reading. For some reason, a socket that does not have data on the wire continues to read and never returns. Is there a way to exit reception after a timeout?

I am using the winsock library.

+5
source share
1 answer

http://tangentsoft.net/wskfaq/newbie.html#timeout

2.15 - How to change the timeout for a Winsock function?

Winsock (, connect()) -, . , , . , , , , ; .

- () recv() SO_SNDTIMEO SO_RCVTIMEO setsockopt()..

Winsock . -:

Non-blocking sockets with select() – The fifth parameter to the select() function is a timeout value.

Asynchronous sockets – Use the Windows API SetTimer().

Event objects – WSAWaitForMultipleEvents() has a timeout parameter.

Waitable Timers – Call CreateWaitableTimers() to make a waitable timer, which you can then pass to a function like WSAEventSelect() along with your sockets: if none of the sockets is signalled before the timer goes off, the blocking function will return anyway.

, -. , Winsock . , , , , Winsocks, .

+9

All Articles