Skip to content

Commit

Permalink
libvncserver: continuous updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Samokhatko committed Mar 16, 2023
1 parent c06e76c commit 8941e02
Show file tree
Hide file tree
Showing 10 changed files with 1,135 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ set(LIBVNCSERVER_SOURCES
${LIBVNCSERVER_DIR}/ultra.c
${LIBVNCSERVER_DIR}/scale.c
${CRYPTO_SOURCES}
${LIBVNCSERVER_DIR}/flowcontrol.c
${LIBVNCSERVER_DIR}/rfbtimers.c
)

Expand Down
42 changes: 42 additions & 0 deletions include/rfb/rfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ extern "C"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rfb/rfblist.h>
#include <rfb/rfbproto.h>
#include <rfb/rfbtimers.h>

#if defined(ANDROID) || defined(LIBVNCSERVER_HAVE_ANDROID)
#include <arpa/inet.h>
Expand Down Expand Up @@ -372,9 +374,18 @@ typedef struct _rfbScreenInfo
#ifdef LIBVNCSERVER_HAVE_LIBZ
rfbSetXCutTextUTF8ProcPtr setXCutTextUTF8;
#endif
rfbBool rfbCongestionControl;
} rfbScreenInfo, *rfbScreenInfoPtr;


typedef struct {
struct timeval tv;
unsigned pos, extra;
char congested;
struct rfb_list entry;
} rfbRTTInfo;


/**
* rfbTranslateFnType is the type of translation functions.
*/
Expand Down Expand Up @@ -707,6 +718,34 @@ typedef struct _rfbClientRec {
int tightPngDstDataLen;
#endif
#endif

/* flow control extensions */

rfbBool enableCU; /**< client supports Continuous Updates */
rfbBool enableFence; /**< client supports fence extension */

rfbBool continuousUpdates;
sraRegionPtr cuRegion;

rfbTimersPtr timers;

rfbBool pendingSyncFence, syncFence;
uint32_t fenceFlags;
unsigned fenceDataLen;
char fenceData[64];

unsigned lastPosition, extraBuffer;
struct timeval lastUpdate, lastSent;
unsigned baseRTT, congWindow;
rfbBool inSlowStart;
int sockOffset;
struct rfb_list pings;
rfbTimerPtr congestionTimer;
rfbRTTInfo lastPong;
struct timeval lastPongArrival;
int measurements;
struct timeval lastAdjustment;
unsigned minRTT, minCongestedRTT;
} rfbClientRec, *rfbClientPtr;

/**
Expand Down Expand Up @@ -755,9 +794,12 @@ extern int rfbMaxClientWait;

extern void rfbInitSockets(rfbScreenInfoPtr rfbScreen);
extern void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen);
extern void rfbCorkSock(int sock);
extern void rfbUncorkSock(int sock);
extern void rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen);
extern void rfbCloseClient(rfbClientPtr cl);
extern int rfbReadExact(rfbClientPtr cl, char *buf, int len);
extern int rfbSkipExact(rfbClientPtr cl, int len);
extern int rfbReadExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
extern int rfbPeekExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
extern int rfbWriteExact(rfbClientPtr cl, const char *buf, int len);
Expand Down
60 changes: 60 additions & 0 deletions include/rfb/rfbproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,20 @@ typedef struct {
/* Modif cs@2005 */
/* PalmVNC 1.4 & 2.0 SetScale Factor message */
#define rfbPalmVNCSetScaleFactor 0xF
#define rfbEnableContinuousUpdates 150
#define rfbEndOfContinuousUpdates 150
/* Xvp message - bidirectional */
#define rfbXvp 250
/* SetDesktopSize client -> server message */
#define rfbSetDesktopSize 251
#define rfbQemuEvent 255


/*-----------------------------------------------------------------------------
* server -> client and client -> server
*/

#define rfbFence 248


/*****************************************************************************
Expand Down Expand Up @@ -528,6 +535,9 @@ typedef struct {
#define rfbEncodingQualityLevel8 0xFFFFFFE8
#define rfbEncodingQualityLevel9 0xFFFFFFE9

#define rfbEncodingContinuousUpdates 0xFFFFFEC7
#define rfbEncodingFence 0xFFFFFEC8

#define rfbEncodingQemuExtendedKeyEvent 0xFFFFFEFE /* -258 */
#define rfbEncodingExtendedClipboard 0xC0A1E5CE

Expand All @@ -538,6 +548,37 @@ typedef struct {
#define rfbEncodingServerIdentity 0xFFFE0003


/*****************************************************************************
*
* Message definitions (server -> client and client -> server)
*
*****************************************************************************/

/*-----------------------------------------------------------------------------
* Fence
*/

/* flags */
#define rfbFenceFlagBlockBefore 1
#define rfbFenceFlagBlockAfter 2
#define rfbFenceFlagSyncNext 4
#define rfbFenceFlagRequest 0x80000000
#define rfbFenceFlagsSupported (rfbFenceFlagBlockBefore | \
rfbFenceFlagBlockAfter | \
rfbFenceFlagSyncNext | \
rfbFenceFlagRequest)

typedef struct _rfbFenceMsg {
uint8_t type; /* always rfbFence */
uint8_t pad[3];
uint32_t flags;
uint8_t length;
/* Followed by char data[length] */
} rfbFenceMsg;

#define sz_rfbFenceMsg 9


/*****************************************************************************
*
* Server -> client message definitions
Expand Down Expand Up @@ -1267,6 +1308,7 @@ typedef union {
rfbTextChatMsg tc;
rfbXvpMsg xvp;
rfbExtDesktopSizeMsg eds;
rfbFenceMsg f;
} rfbServerToClientMsg;


Expand Down Expand Up @@ -1523,6 +1565,22 @@ typedef struct _rfbSetSWMsg {
#define sz_rfbSetSWMsg 6


/*-----------------------------------------------------------------------------
* EnableContinuousUpdates
*/

typedef struct _rfbEnableContinuousUpdatesMsg {
uint8_t type; /* always rfbEnableContinuousUpdates */
uint8_t enable;
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
} rfbEnableContinuousUpdatesMsg;

#define sz_rfbEnableContinuousUpdatesMsg 10



/*-----------------------------------------------------------------------------
* Union of all client->server messages.
Expand All @@ -1545,6 +1603,8 @@ typedef union {
rfbTextChatMsg tc;
rfbXvpMsg xvp;
rfbSetDesktopSizeMsg sdm;
rfbEnableContinuousUpdatesMsg ecu;
rfbFenceMsg f;
} rfbClientToServerMsg;

/*
Expand Down
1 change: 1 addition & 0 deletions include/rfb/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#endif
#elif defined(LIBVNCSERVER_HAVE_WIN32THREADS)
#include <process.h>
#include <windows.h>
#define LOCK(mutex) EnterCriticalSection(&(mutex))
#define UNLOCK(mutex) LeaveCriticalSection(&(mutex))
#define MUTEX(mutex) CRITICAL_SECTION (mutex)
Expand Down
4 changes: 4 additions & 0 deletions src/libvncserver/cargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ rfbUsage(void)
"new non-shared\n"
" connection comes in (refuse new connection "
"instead)\n");
fprintf(stderr, "-noflowcontrol when continuous updates are enabled, send updates\n"
" whether or not the viewer is ready to receive them\n");
#ifdef LIBVNCSERVER_WITH_WEBSOCKETS
fprintf(stderr, "-sslkeyfile path set path to private key file for encrypted WebSockets connections\n");
fprintf(stderr, "-sslcertfile path set path to certificate file for encrypted WebSockets connections\n");
Expand Down Expand Up @@ -158,6 +160,8 @@ rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[])
rfbScreen->neverShared = TRUE;
} else if (strcmp(argv[i], "-dontdisconnect") == 0) {
rfbScreen->dontDisconnect = TRUE;
} else if (strcmp(argv[i], "-noflowcontrol") == 0) {
rfbScreen->rfbCongestionControl = FALSE;
} else if (strcmp(argv[i], "-httpdir") == 0) { /* -httpdir directory-path */
if (i + 1 >= *argc) {
rfbUsage();
Expand Down
Loading

0 comments on commit 8941e02

Please sign in to comment.