mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
Remove read timeouts. In order to be still able to detect disconnected clients, send empty framebuffer requests every 10s if there is nothing else to send. Hopefully this solves tieout problems with windows vnc clients.
svn path=/trunk/kdenetwork/krfb/; revision=193264
This commit is contained in:
@@ -455,7 +455,7 @@ void RFBController::connectionAccepted(bool aRC)
|
||||
emit sessionEstablished();
|
||||
}
|
||||
|
||||
void RFBController::acceptConnection(bool aRC)
|
||||
void RFBController::acceptConnection(bool aRemoteControl)
|
||||
{
|
||||
KNotifyClient::event("UserAcceptsConnection",
|
||||
i18n("User accepts connection from %1")
|
||||
@@ -464,7 +464,7 @@ void RFBController::acceptConnection(bool aRC)
|
||||
if (state != RFB_CONNECTING)
|
||||
return;
|
||||
|
||||
connectionAccepted(aRC);
|
||||
connectionAccepted(aRemoteControl);
|
||||
rfbStartOnHoldClient(server->rfbClientHead);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ typedef int socklen_t;
|
||||
#include "rfb.h"
|
||||
#include "sraRegion.h"
|
||||
|
||||
/* minimum interval between attempts to send something */
|
||||
#define PING_MS 10000
|
||||
|
||||
MUTEX(logMutex);
|
||||
|
||||
int rfbEnableLogging=1;
|
||||
@@ -257,11 +260,13 @@ clientOutput(void *data)
|
||||
UNLOCK(cl->updateMutex);
|
||||
|
||||
if (!haveUpdate) {
|
||||
WAIT(cl->updateCond, cl->updateMutex);
|
||||
TIMEDWAIT(cl->updateCond, cl->updateMutex, PING_MS);
|
||||
UNLOCK(cl->updateMutex); /* we really needn't lock now. */
|
||||
if (!haveUpdate)
|
||||
rfbSendPing(cl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* OK, now, to save bandwidth, wait a little while for more
|
||||
updates to come along. */
|
||||
usleep(cl->screen->rfbDeferUpdateTime * 1000);
|
||||
|
||||
@@ -151,6 +151,10 @@ typedef unsigned long KeySym;
|
||||
#define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
|
||||
#define TSIGNAL(cond) pthread_cond_signal(&(cond))
|
||||
#define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
|
||||
#define TIMEDWAIT(cond,mutex,t) {struct timeval tv;\
|
||||
tv.tv_sec = (t) / 1000;\
|
||||
tv.tv_usec = ((t) % 1000) * 1000;\
|
||||
pthread_cond_timedwait(&(cond),&(mutex),&tv);}
|
||||
#define COND(cond) pthread_cond_t (cond)
|
||||
#define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
|
||||
#define TINI_COND(cond) pthread_cond_destroy(&(cond))
|
||||
@@ -620,6 +624,7 @@ extern void rfbProcessClientMessage(rfbClientPtr cl);
|
||||
extern void rfbClientConnFailed(rfbClientPtr cl, char *reason);
|
||||
extern void rfbNewUDPConnection(rfbScreenInfoPtr rfbScreen,int sock);
|
||||
extern void rfbProcessUDPInput(rfbScreenInfoPtr rfbScreen);
|
||||
extern Bool rfbSendPing(rfbClientPtr cl);
|
||||
extern Bool rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion);
|
||||
extern Bool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
|
||||
extern Bool rfbSendUpdateBuf(rfbClientPtr cl);
|
||||
|
||||
@@ -909,6 +909,22 @@ rfbProcessClientNormalMessage(cl)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rfbSendPing - send an empty framebuffer request
|
||||
*/
|
||||
|
||||
Bool
|
||||
rfbSendPing(cl)
|
||||
rfbClientPtr cl;
|
||||
{
|
||||
rfbFramebufferUpdateMsg *fu = (rfbFramebufferUpdateMsg *)cl->updateBuf;
|
||||
cl->rfbFramebufferUpdateMessagesSent++;
|
||||
fu->type = rfbFramebufferUpdate;
|
||||
fu->nRects = Swap16IfLE((CARD16)0);
|
||||
cl->ublen = sz_rfbFramebufferUpdateMsg;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rfbSendFramebufferUpdate - send the currently pending framebuffer update to
|
||||
|
||||
@@ -369,7 +369,8 @@ rfbConnect(rfbScreen, host, port)
|
||||
/*
|
||||
* ReadExact reads an exact number of bytes from a client. Returns 1 if
|
||||
* those bytes have been read, 0 if the other end has closed, or -1 if an error
|
||||
* occurred (errno is set to ETIMEDOUT if it timed out).
|
||||
* occurred (errno is set to ETIMEDOUT if it timed out).
|
||||
* timeout is the timeout in ms, 0 for no timeout.
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -379,6 +380,9 @@ ReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
|
||||
int n;
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
int to = 20000;
|
||||
if (timeout)
|
||||
to = timeout;
|
||||
|
||||
while (len > 0) {
|
||||
n = read(sock, buf, len);
|
||||
@@ -402,14 +406,14 @@ ReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(sock, &fds);
|
||||
tv.tv_sec = timeout / 1000;
|
||||
tv.tv_usec = (timeout % 1000) * 1000;
|
||||
tv.tv_sec = to / 1000;
|
||||
tv.tv_usec = (to % 1000) * 1000;
|
||||
n = select(sock+1, &fds, NULL, &fds, &tv);
|
||||
if (n < 0) {
|
||||
rfbLogPerror("ReadExact: select");
|
||||
return n;
|
||||
}
|
||||
if (n == 0) {
|
||||
if ((n == 0) && timeout) {
|
||||
errno = ETIMEDOUT;
|
||||
return -1;
|
||||
}
|
||||
@@ -420,7 +424,7 @@ ReadExactTimeout(rfbClientPtr cl, char* buf, int len, int timeout)
|
||||
|
||||
int ReadExact(rfbClientPtr cl,char* buf,int len)
|
||||
{
|
||||
return(ReadExactTimeout(cl,buf,len,rfbMaxClientWait));
|
||||
return ReadExactTimeout(cl, buf, len, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user