我正在编写一个程序,它将接收消息、接收用户输入(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?