当前位置: 技术问答>linux和unix
select函数的作用是什么呢?谢谢
来源: 互联网 发布时间:2016-04-11
本文导语: 如:麻烦您给个注释谢!!!!!!!!! fd_set rfds; struct timeval tv; if (handle == NULL || received == NULL) return IPAPI_ERR; _IPAPI_Ref(h); FD_ZERO(&rfds); FD_SET(h->out_handle, &rfds);...
如:麻烦您给个注释谢!!!!!!!!!
fd_set rfds;
struct timeval tv;
if (handle == NULL || received == NULL)
return IPAPI_ERR;
_IPAPI_Ref(h);
FD_ZERO(&rfds);
FD_SET(h->out_handle, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 250000;
rc = select(h->out_handle + 1, &rfds, NULL, NULL, &tv);
fd_set rfds;
struct timeval tv;
if (handle == NULL || received == NULL)
return IPAPI_ERR;
_IPAPI_Ref(h);
FD_ZERO(&rfds);
FD_SET(h->out_handle, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 250000;
rc = select(h->out_handle + 1, &rfds, NULL, NULL, &tv);
|
就是当select调用开始的250ms以内,如果h_out_handle这个句柄有数据可读了,刚select会返回大于0,这样你去read一般来说都会成功的,如果在这个时间段内没有数据可读则返回0指示超时了,异常返回小于0,最常见的就是被其它信号中断了,此时errno为EINTR.