I know both of this can be used to set timeout of recvfrom(), but which one is better? Intuitively, setsockopt seems simple to use, but I found many examples are using select(). I only use a single socket and the timeout is recalculated in transmission(I am using Ubuntu).
Asked
Active
Viewed 1,447 times
1
-
Can you share some additional information on the exact scenario of timeout that you are looking to use these for ? – Karthik Balaguru Oct 29 '15 at 21:44
-
Some platforms, Solaris I believe for example, don't support `SO_RCVTIMEO`, so `select()` is your only choice there. – user207421 Oct 30 '15 at 04:05
1 Answers
0
It depends on your exact requirement/scenario that you are looking to use it.
In general, select allows you to monitor several sockets at the same time. Incase your design has multiple sockets, then usage of select is preferred. However, if you are going to have only one socket, then the option of using timeout (SO_RCVTIMEO) with setsockopt is a better option.

Karthik Balaguru
- 7,424
- 7
- 48
- 65
-
If I use setsockopt, how can I cancel the timeout to set recvfrom() keeping blocking? – Rapidturtle Oct 30 '15 at 05:23
-
You can disable timeout by configuring the seconds and microseconds to zero. – Karthik Balaguru Oct 30 '15 at 16:45