当前位置: 技术问答>linux和unix
accept阻塞问题
来源: 互联网 发布时间:2017-01-13
本文导语: 本帖最后由 zsjay758 于 2011-11-04 11:06:12 编辑 有如下代码: //设置非阻塞模式 int flags = fcntl(sublistenfd, F_GETFL, 0); fcntl(sublistenfd, F_SETFL, flags | O_NONBLOCK); fd_set rset,allset; FD_ZERO(&rset); FD_ZERO(&allset); FD_SET(sublistenfd,...
//设置非阻塞模式
int flags = fcntl(sublistenfd, F_GETFL, 0);
fcntl(sublistenfd, F_SETFL, flags | O_NONBLOCK);
fd_set rset,allset;
FD_ZERO(&rset);
FD_ZERO(&allset);
FD_SET(sublistenfd,&allset);
int nready = 0;
int maxfd = sublistenfd +1;
//超时设置
struct timeval timeout,resettime;
timeout.tv_sec = g_nTimeout;//TIMEOUT;
timeout.tv_usec = 0;
int nCliLen = 0;
for ( ; ; )
{
rset = allset;
resettime = timeout;
nready = select(maxfd, &rset, NULL, NULL, &resettime);
if(nready