您的位置:首页 > 运维架构 > Linux

一个linux典型的select模型更新方法

2008-03-22 11:16 549 查看
bool update(int _fd, int _timeout, char *buffer){



//cout << "update +++++++" << endl;

fd_set fdClient;



FD_ZERO( &fdClient );

FD_SET( _fd, &fdClient );



struct timeval tv;



tv.tv_sec = _timeout;

tv.tv_usec = 0;





if( select( _fd + 1, &fdClient, NULL, NULL, &tv ) == -1 ) {

return true;

}



if( FD_ISSET( _fd, &fdClient ) ) {

memset( buffer, 0, sizeof( char ) * GPBUF_SIZE );



int c = recv( _fd, buffer, GPBUF_SIZE, 0 );



if( c == -1 && errno != EWOULDBLOCK ) {

if( errno != ECONNRESET )

//cout << "peer reset the connection" << endl;

return true;

}

if( c == 0 )

return true;



}

return false;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐