简体   繁体   中英

About socket connection timeout in C++ (UNIX)

I have been working to put a 15 seconds timeout to a socket to avoid it to be blocked. So i configured it as non-blocking, then used select function, and works fine... when the computer is connected to a network!

If computer is disconnected from the network (for example, if Wi-Fi signal is turned off, or if you emove the ethernet plug), when I call connect function it returns inmediatly the "Network is unreachable" error.

Since I have a loop to get it reconnected if something like this happens, it is trying to connect MANY times, so I'm getting log files of gigabytes.

So, what I want is to set some kind of timeout for that too. It's not a timeout actually, but I want it to wait 15 seconds until it tries to connect again to avoid this problem. I was wrong when I thought that the timeout i have set as explained in paragraph 1 would fix this too. How can I make this then?

如果它是ENETUNREACH你可以测试errnosleep

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM