读书人

select回到1但是recv返回-1err =

发布时间: 2013-06-25 23:45:41 作者: rapoo

select返回1,但是recv返回-1,err = 10035
fd_set rfds;
struct timeval tv;
memset( &tv, 0, sizeof(tv) );
tv.tv_usec = 20;
int nRet = 0;
int ncount = 0;
char szBuf[BUF_SIZE] = {0};
FD_ZERO( &rfds );
FD_SET( pClient->m_cliSocket, &rfds );
try
{
ncount = select(0, &rfds, NULL, NULL, &tv);
if(0 == ncount)
{
nRet = 0;
}
else if ( ncount > 0 )//have data
{
if (FD_ISSET(pClient->m_cliSocket,&rfds)) //判断为假,recv无法执行
{
ncount = recv( pClient->m_cliSocket, szBuf, sizeof(szBuf) - 1, 0 );

以上是部分代码,select返回1,但是recv返回-1,错误码为10035
这是什么情况?select返回1不是说明有数据可读吗? select
[解决办法]
查一下10035 错误是什么?
[解决办法]
无法立即完成一个非阻塞套接字操作。
套接字不阻塞,而指定操作将使之阻塞。
Operation would block.

WSAEWOULDBLOCK
(10035)
Resource temporarily unavailable.
This error is returned from operations on non-blocking sockets that cannot be completed immediately, for example recv when no data is queued to be read from the socket. It is a non-fatal error, and the operation should be retried later. It is normal for WSAEWOULDBLOCK to be reported as the result from calling connect on a non-blocking SOCK_STREAM socket, since some time must elapse for the connection to be established.

读书人网 >C++

热点推荐