我是网络编程的新手,正在尝试工作和测试 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;
}