选择返回零,但有更多的数据和recv工作太
select return zero but there are more data and recv works too
我正在使用LibVNC,通过打开日志(显示发送和接收的字节),我可以看到服务器正在发送数据。但我的客户在某一时刻停止接收数据。我调试了它,并进入:在我的客户端选择函数返回零值。虽然如果我通过调试器更改返回值,recv继续工作并按照从服务器发布的顺序接收数据。所以看起来一切都很好。
我在同一台机器上运行客户端和服务器,所以使用localhost.
我不知道它是否有帮助,但这是一段返回零的代码。
有什么建议我应该在哪里挖掘问题吗?
int WaitForMessage(rfbClient* client,unsigned int usecs)
{
fd_set fds;
struct timeval timeout;
int num;
timeout.tv_sec=(usecs/1000000);
timeout.tv_usec=(usecs%1000000);
FD_ZERO(&fds);
FD_SET(client->sock,&fds);
num=select(client->sock+1, &fds, NULL, NULL, &timeout);
if(num<0) {
errno=WSAGetLastError();
rfbClientLog("Waiting for message failed: %d (%s)n",errno,strerror(errno));
}
return num;
}
select()
在其timeout
周期结束时返回0,因此请仔细检查timeout
是否准确。请记住,tv_sec
以秒表示,tv_usec
以微秒(1/1000000秒)表示。您的usecs
参数用什么表示?在Windows编程中,微秒是非常不常见的,毫秒(1/1000秒)更常见。当select()
返回0时,在usecs
参数中指定什么值?有可能您没有正确处理usecs
,结果timeout
比您期望的要小得多。
相关文章:
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- C++ TCP 套接字通信 - 连接按预期工作,几秒钟后失败,没有收到新数据,read() 和 recv() 块
- 在UNIX中通过recv/send交换数据时,如何正确使用缓冲区
- 为什么 sys 套接字 recv 函数不填充数据但返回字节长度?
- C++ 即使数据可用,Windows recv() 也不会返回
- 为 posix recv 设置超时会导致 udp 数据包丢失吗?
- C 非阻止等待所有RECV数据
- recv() 获取损坏的数据
- Winsock recv() 返回不正确的数据
- 如何使用 winsock (c++) 发送recv 非字符数据
- recv (Winsock) 函数挂起,但数据可用
- C++ 绕道 Winsock recv 挂钩 - 自定义数据包
- C++ WinSock Recv 在接收 0 数据时终止线程而不是返回错误代码
- 如何使用c++使用recv()函数接收大数据
- 使用 recv() 接收部分数据是可能的
- 在本地将数据填充到recv缓冲区中
- 由于PROTOBUF服务器中的字符串数据类型变量和客户端通过cpp中recv端的套接字进行通信,因此正在获取segfau
- 套接字发送数据,但 recv 程序无法正常工作
- UDP套接字是否将接收到的数据划分为不同的消息,或者recv是否同时读取尽可能多的数据
- C++"recv"函数在数据接收时如何起作用?它能收到部分"packet"吗?