初步建立一下对 select() 函数的印象_1
程序代码:
#include <stdio.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> int main(void) { fd_set rfds; struct timeval tv; int retval; FD_ZERO(&rfds); FD_SET(0, &rfds); tv.tv_sec = 5; tv.tv_usec = 0; retval = select( 1, &rfds, NULL, NULL, &tv); if( retval == -1 ) perror( "select()" ); else if(retval) /* FD_ISSET(0, &rfds) will be true */ printf("Data is available now.\n"); else printf("No data within five seconds.\n"); return 0; }
编译运行一下可以对select()有一个直观的感觉了
[ 本帖最后由 madfrogme 于 2012-8-30 09:17 编辑 ]