ieuan25 / HttpServer

2 stars 0 forks source link

Socket accept has to time out #6

Closed kybu closed 10 years ago

kybu commented 10 years ago

As we spoke, this is a beginning of having a main event loop. Start with using signals to interrupt the accept call. Have a look at alarm call. It sets an alarm signal to be emitted. When that happens, the accept call will return EINTR.

This is an old fashioned way used only in simple cases nowadays. We will go through "the whole picture" after you implement alarms.

ieuan25 commented 10 years ago

I've added some code to do this. I'm just ignoring EINTR after the socket accept call. Could you take a quick look at the commit and let me know what you think? I'm going to do it properly this weekend and clean up my main function but would be good to get feedback on what I've done.

kybu commented 10 years ago

Done. See my comments in the code.

kybu commented 10 years ago

Also, alarm() should logically be a part of getClientSocket() and not being in the main loop. There is a potential problem with the alarm reset as well. It is at the very end of the main loop which means that the alarm might be fired between getClientSocket() and the end of the loop. Another system call can be interrupted by it which is something you didn't intent to do. Change it so that getClientSocket() takes care of timeouts and not the part which uses the Connection class.