Article From:

There are 3 ways to set timeouts on I/O operations involving sockets:

(1)Call alarm, which generates SIGALRM signals at a specified period of full time, which involves signal processing, and signal processing varies on different implementations, and may interfere with the existing alarm calls in the process.

(2)In select, blocking wait for I/O (select has built-in time limit) instead of directly blocking read or write calls.

(3)With the newer SO_RECVTIMEO and SO_SNDTIMEO socket options, the problem with this method is that not all implementations support these two socket options.

The above is from “UNIX Network Programming Volume 1: socket networking API”.

Recently, when setting up a project, set up the socket timeout, first thought of (2), and racked my brains to think about how to modify the code. Colleagues remind you to use the way (3), and finally modify the less code, realize the timeout control function.


Link of this Article: Socket timeout

Leave a Reply

Your email address will not be published. Required fields are marked *