当前位置: 技术问答>linux和unix
select 到底怎么用?
来源: 互联网 发布时间:2015-01-12
本文导语: 谢谢。 | fd_set readfds; fd_set exceptfds; timeval tmOut; tmOut.tv_sec = 120; tmOut.tv_usec = 0; FD_ZERO( &readfds ); FD_ZERO( &exceptfds ); FD_SET( scSocket, &exceptfds ); FD_SET( scSocket, &readfds ); ... int iRet = select( scS...
谢谢。
|
fd_set readfds;
fd_set exceptfds;
timeval tmOut;
tmOut.tv_sec = 120;
tmOut.tv_usec = 0;
FD_ZERO( &readfds );
FD_ZERO( &exceptfds );
FD_SET( scSocket, &exceptfds );
FD_SET( scSocket, &readfds );
...
int iRet = select( scSocket + 1, &readfds, NULL, &exceptfds, &tmOut );
if( iRet == 0 ) //超时
{
return -2;
}
if( FD_ISSET( scSocket, &exceptfds ) )
{ //连接被终止
return -1;
}
iRet = recv( scSocket, szBuff, iSize, 0 );
...
fd_set exceptfds;
timeval tmOut;
tmOut.tv_sec = 120;
tmOut.tv_usec = 0;
FD_ZERO( &readfds );
FD_ZERO( &exceptfds );
FD_SET( scSocket, &exceptfds );
FD_SET( scSocket, &readfds );
...
int iRet = select( scSocket + 1, &readfds, NULL, &exceptfds, &tmOut );
if( iRet == 0 ) //超时
{
return -2;
}
if( FD_ISSET( scSocket, &exceptfds ) )
{ //连接被终止
return -1;
}
iRet = recv( scSocket, szBuff, iSize, 0 );
...