|
You can't do that.
Your accept() should be able to either block or not block at your control. If you turned on a non-blocking option on the socket, then yes your accept() call will return an error if there are no pending connections. If you then decide to sleep(), then any connections that arrive while your server is asleep will become become pending connections. After the sleep(), it could re-issue the accept() and establish a connection.
Turning on a non-blocking option and then polling from time to time is supposed to work. But I have never seen it done. I would not sleep for 300 seconds though. That is a very long time to keep a connection waiting for a connect.
But the usual method is to allow accept() to block and wait for a connection to occur.
If your accept() is not blocking then somehow you must have asked it not to. The usual way of doing this would be to have set O_NONBLOCK.
If your accept() call does not behave as I described, then it must be broken. But I find that hard to believe. Never blocking would be a very serious problem.
|