Thursday, September 30, 2010

self pipe trick

Our old red hat Linux kernel does not support pselect(), so we have to use self pipe trick to handle it. In a select loop, we have to monitor both the file descriptors and signal. Whenever one of them happens, it should not block. For example,
while (1)
{
if (shutdownSignal)
     //do shutdown
<===== The shutdown signal may come here
select (socketfd);
}
When no traffic sent through, and the select may block here until somebody send some data.

Or you can use  siglongjmp, which will jump out from the signal handler even if you are inside of the select() call.

No comments: