我正在编写一个程序,它将接收消息,接收用户输入(STDIN)并向其他服务器发送定期消息。所以我在程序中使用了 select()。下面是伪代码:
// master is the fd set
FD_SET(0, &master); // add STDIN into master set
FD_SET(listener, &master); // listener is the listening UDP socket
int indicator = select(...args...);
// have data coming in
if(indicator > 0 ){
// do something
}
// user input some data
else if(indicator == 0){
// do something if user input data
}
//Here is the question. How can I differentiate STDIN from timeout?
else if(){
// do something if timeout occurred
}
我想知道有没有办法区分超时与STDIN,因为在这种情况下两者都会使select()返回0?