选择返回零,但有更多的数据和recv工作太

select return zero but there are more data and recv works too

本文关键字:数据 recv 工作 返回 选择      更新时间:2023-10-16

我正在使用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比您期望的要小得多。