0
votes

does anyone know if you can set a timeout for a listening socket? I know that you can use a timeout for a send/recv action with SO_RCVTIMEO and SO_SNDTIMEO (through setsockopt) but in my case I need to set that timeout for a socket in a listen state. If no connection is established in X time, I closed the socket. Do you know any socket option to get that?

Thank you.

1
You can use the select() function which is for that purpose. If the socket is read(able) means that you can use the accept() without blocking. If select() return 0 means the timeout has elapsed. - ja_mesa

1 Answers

1
votes

Yes, you can set SO_RCVTIMEO and it will timeout the accept() method.