winsock2 select()错误 - 结果太大

时间:2013-07-14 05:49:21

标签: c sockets vnc

我是网络编程的新手,正在尝试工作&测试一个vnc服务器。我正在使用mingw并链接到LibVNCServer(我在本地构建的DLL)库

我的主程序在喜欢DLL之后编译并且可以作为端口5900上的侦听服务器运行,当我尝试使用telnet或vnc客户端程序连接到此服务器时,我得到“选择中的错误:结果太大”重复错误来自服务器控制台,这来自以下行

if (select(rfbScreen->maxFd+1, &listen_fds, NULL, NULL, NULL) == -1) {
      rfbLogPerror("rfbProcessNewConnection: error in select");
      return FALSE;
    }

错误编号为errno = 34,可以通过以下mingw代码段匹配http://wiki.rocrail.net/doku.php?id=win32-mingw-error&DokuWiki=mystpihv

请参阅下文,了解vncserver代码库

文件“sockets.c”中的更多位代码
rfbBool rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
{
    const int one = 1;
    int sock = -1;
#ifdef LIBVNCSERVER_IPv6
    struct sockaddr_storage addr;
#else
    struct sockaddr_in addr;
#endif
    socklen_t addrlen = sizeof(addr);
    fd_set listen_fds; 
    int chosen_listen_sock = -1;

    /* Do another select() call to find out which listen socket
       has an incoming connection pending. We know that at least 
       one of them has, so this should not block for too long! */
    FD_ZERO(&listen_fds);  
    if(rfbScreen->listenSock >= 0) 
      FD_SET(rfbScreen->listenSock, &listen_fds);
    if(rfbScreen->listen6Sock >= 0) 
      FD_SET(rfbScreen->listen6Sock, &listen_fds);
    if (select(rfbScreen->maxFd+1, &listen_fds, NULL, NULL, NULL) == -1) {
      rfbLogPerror("rfbProcessNewConnection: error in select");
      return FALSE;
    }
    if (FD_ISSET(rfbScreen->listenSock, &listen_fds)) 
      chosen_listen_sock = rfbScreen->listenSock;
    if (FD_ISSET(rfbScreen->listen6Sock, &listen_fds)) 
      chosen_listen_sock = rfbScreen->listen6Sock;

    if ((sock = accept(chosen_listen_sock,
               (struct sockaddr *)&addr, &addrlen)) < 0) {
      rfbLogPerror("rfbCheckFds: accept");
      return FALSE;
    }

    if(!rfbSetNonBlocking(sock)) {
      closesocket(sock);
      return FALSE;
    }

    if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
           (char *)&one, sizeof(one)) < 0) {
      rfbLogPerror("rfbCheckFds: setsockopt");
      closesocket(sock);
      return FALSE;
    }

#ifdef USE_LIBWRAP
    if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
          STRING_UNKNOWN)) {
      rfbLog("Rejected connection from client %s\n",
         inet_ntoa(addr.sin_addr));
      closesocket(sock);
      return FALSE;
    }
#endif

#ifdef LIBVNCSERVER_IPv6
    char host[1024];
    if(getnameinfo((struct sockaddr*)&addr, addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST) != 0) {
      rfbLogPerror("rfbProcessNewConnection: error in getnameinfo");
    }
    rfbLog("Got connection from client %s\n", host);
#else
    rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
#endif

    rfbNewClient(rfbScreen,sock);

    return TRUE;
}

我还需要链接器路径中的Ws2_32.dlls吗?

修改

=== main.c ===

#include <iostream>
#include <stdio.h>
#include "rfb/rfb.h"

using namespace std;

int main(int argc, char** argv) {
    rfbScreenInfoPtr server = rfbGetScreen(&argc, argv, 400, 300, 8, 3, 4);
    server->frameBuffer = (char*)malloc(400 * 300 * 4);
    rfbInitServer(server);
    rfbRunEventLoop(server, -1, FALSE);
    return 0;
}

0 个答案:

没有答案