2012年5月21日 星期一
Linux C Select() - multi input trace
fd_set set;
FD_ZERO(&set); /*clear set */
FD_SET(fd, &set); /*add fd into set */
FD_CLR(fd, &set); /*remove fd from set*/
FD_ISSET(fd, &set); /*return true if fd is in set*/
------------------------------------------------------------------------
int maxfd = MAX (fd1, fd2)+1;
struct timeval tv;
tv.tv_usec = 0;
tv.tv_sec = 2;
while (1) {
FD_SET(fd1, &readfs); /* input 1*/
FD_SET(fd2, &readfs); /* input 2 */
/* block until input becomes available */
int rul = select(maxfd, &readfs, NULL, NULL, &tv );
if (FD_ISSET(fd1)) /* if input 1 has signal*/
handle_input_from_source1();
if (FD_ISSET(fd2)) /* if input 2 has signal */
handle_input_from_source2();
/*
if(rul == -1)
return errorout;
if(rul == 0)
return timeout;
*/
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言