Commit 9f8d8d4e authored by George Kiagiadakis's avatar George Kiagiadakis Committed by Christian Beier

Split two event-loop related functions out of the rfbProcessEvents() mechanism.

This is required to be able to do proper event loop integration with Qt.
Idea was taken from vino's libvncserver fork.
Signed-off-by: 's avatarChristian Beier <dontmind@freeshell.org>
parent c8b89381
......@@ -1085,6 +1085,26 @@ rfbProcessEvents(rfbScreenInfoPtr screen,long usec)
i = rfbGetClientIteratorWithClosed(screen);
cl=rfbClientIteratorHead(i);
while(cl) {
result = rfbUpdateClient(cl);
clPrev=cl;
cl=rfbClientIteratorNext(i);
if(clPrev->sock==-1) {
rfbClientConnectionGone(clPrev);
result=TRUE;
}
}
rfbReleaseClientIterator(i);
return result;
}
rfbBool
rfbUpdateClient(rfbClientPtr cl)
{
struct timeval tv;
rfbBool result=FALSE;
rfbScreenInfoPtr screen = cl->screen;
if (cl->sock >= 0 && !cl->onHold && FB_UPDATE_PENDING(cl) &&
!sraRgnEmpty(cl->requestedRegion)) {
result=TRUE;
......@@ -1126,14 +1146,6 @@ rfbProcessEvents(rfbScreenInfoPtr screen,long usec)
}
}
}
clPrev=cl;
cl=rfbClientIteratorNext(i);
if(clPrev->sock==-1) {
rfbClientConnectionGone(clPrev);
result=TRUE;
}
}
rfbReleaseClientIterator(i);
return result;
}
......
......@@ -260,37 +260,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) {
if ((sock = accept(rfbScreen->listenSock,
(struct sockaddr *)&addr, &addrlen)) < 0) {
rfbLogPerror("rfbCheckFds: accept");
return -1;
}
if(!rfbSetNonBlocking(sock)) {
closesocket(sock);
return -1;
}
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
rfbLogPerror("rfbCheckFds: setsockopt");
closesocket(sock);
return -1;
}
#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 -1;
}
#endif
rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
rfbNewClient(rfbScreen,sock);
rfbProcessNewConnection(rfbScreen);
FD_CLR(rfbScreen->listenSock, &fds);
if (--nfds == 0)
......@@ -352,6 +322,47 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
return result;
}
void
rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
{
const int one = 1;
int sock = -1;
struct sockaddr_in addr;
socklen_t addrlen = sizeof(addr);
if ((sock = accept(rfbScreen->listenSock,
(struct sockaddr *)&addr, &addrlen)) < 0) {
rfbLogPerror("rfbCheckFds: accept");
return -1;
}
if(!rfbSetNonBlocking(sock)) {
closesocket(sock);
return -1;
}
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
(char *)&one, sizeof(one)) < 0) {
rfbLogPerror("rfbCheckFds: setsockopt");
closesocket(sock);
return -1;
}
#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 -1;
}
#endif
rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
rfbNewClient(rfbScreen,sock);
}
void
rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen)
......
......@@ -1003,6 +1003,12 @@ extern void rfbSetProtocolVersion(rfbScreenInfoPtr rfbScreen, int major_, int mi
extern rfbBool rfbSendTextChatMessage(rfbClientPtr cl, uint32_t length, char *buffer);
/*
* Additions for Qt event loop integration
* Original idea taken from vino.
*/
void rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen);
rfbBool rfbUpdateClient(rfbClientPtr cl);
#if(defined __cplusplus)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment