Skip to content

Commit d6082be

Browse files
committedDec 26, 2014
MulticastVNC: port libvncclient to common/ghpringbuf.
1 parent 207fb76 commit d6082be

File tree

5 files changed

+49
-171
lines changed

5 files changed

+49
-171
lines changed
 

‎TODO.multicast

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ BOTH:
5454

5555
- add #ifdef MULTICASTVNC around mcast code
5656

57-
- unify client and server buffer implementation
58-
5957
- Implement other encodings than raw and ultra.
6058

6159
- have an optional server-push mode that's announced by the server

‎libvncserver/Makefile.am

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ include_HEADERS=../rfb/rfb.h ../rfb/rfbconfig.h ../rfb/rfbint.h \
3737

3838
noinst_HEADERS=../common/d3des.h ../rfb/default8x16.h zrleoutstream.h \
3939
zrlepalettehelper.h zrletypes.h private.h scale.h rfbssl.h rfbcrypto.h \
40-
partialupdateregionbuf.h \
41-
../common/minilzo.h ../common/lzoconf.h ../common/lzodefs.h ../common/md5.h ../common/sha1.h \
40+
../common/minilzo.h ../common/lzoconf.h ../common/lzodefs.h ../common/md5.h ../common/sha1.h ../common/ghpringbuf.h \
41+
partialupdateregion.h \
4242
$(TIGHTVNCFILETRANSFERHDRS)
4343

4444
EXTRA_DIST=tableinit24.c tableinittctemplate.c tabletranstemplate.c \
@@ -56,7 +56,7 @@ LIB_SRCS = main.c rfbserver.c rfbregion.c auth.c sockets.c $(WEBSOCKETSSRCS) \
5656
stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
5757
httpd.c cursor.c font.c \
5858
draw.c selbox.c ../common/d3des.c ../common/vncauth.c cargs.c ../common/minilzo.c ultra.c scale.c \
59-
partialupdateregionbuf.c \
59+
../common/ghpringbuf.c \
6060
$(ZLIBSRCS) $(TIGHTSRCS) $(TIGHTVNCFILETRANSFERSRCS)
6161

6262

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
partialupdateregionbuf.h: partial update region ringbuffer header
2+
partialupdateregion.h: partial update region for use with generic ring buffer
33
4-
Copyright (C) 2010 Christian Beier <dontmind@freeshell.org>
4+
Copyright (C) 2014 Christian Beier <dontmind@freeshell.org>
55
66
This is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -20,8 +20,8 @@
2020
*/
2121

2222

23-
#ifndef PARTIALUPDATEREGIONBUF_H
24-
#define PARTIALUPDATEREGIONBUF_H
23+
#ifndef PARTIALUPDATEREGION_H
24+
#define PARTIALUPDATEREGION_H
2525

2626
#include "rfb/rfb.h"
2727

@@ -41,32 +41,15 @@ typedef struct _partialUpdRegion {
4141

4242

4343
/*
44-
the ringbuffer holding partialUpdRegions
45-
*/
46-
typedef struct _partUpdRgnBuf {
47-
partialUpdRegion* partUpdRgns;
48-
size_t len;
49-
size_t nextInsertAt;
50-
rfbBool wraparound;
51-
rfbBool dirty;
52-
} partUpdRgnBuf;
53-
54-
55-
56-
/* creates a new empty partUpdRgnBuf ringbuffer of size length */
57-
partUpdRgnBuf* partUpdRgnBufCreate(size_t length);
58-
59-
/* destroys a partUpdRgnBuf, deallocating all internal data */
60-
void partUpdRgnBufDestroy(partUpdRgnBuf* b);
61-
62-
/* insert a partialUpdRegion into a ringbuffer */
63-
void partUpdRgnBufInsert(partUpdRgnBuf* b, partialUpdRegion partUpdRgn);
64-
65-
/* get partialUpdRegion at index */
66-
partialUpdRegion* partUpdRgnBufAt(partUpdRgnBuf* b, size_t index);
44+
cleaner function for the ring buffer
45+
*/
46+
static void clean_partialUpdRegion(void *p)
47+
{
48+
partialUpdRegion *pur = (partialUpdRegion*)p;
49+
if(pur->region)
50+
sraRgnDestroy(pur->region);
51+
}
6752

68-
/* get number of buffered elements */
69-
size_t partUpdRgnBufCount(partUpdRgnBuf* b);
7053

7154

7255
#endif

‎libvncserver/partialupdateregionbuf.c

-111
This file was deleted.

‎libvncserver/rfbserver.c

+34-26
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#include <string.h>
3737
#include <rfb/rfb.h>
3838
#include <rfb/rfbregion.h>
39-
#include "partialupdateregionbuf.h"
39+
#include "ghpringbuf.h"
40+
#include "partialupdateregion.h"
4041
#include "private.h"
4142

4243

@@ -124,6 +125,7 @@ static const int tight2turbo_subsamp[10] = {
124125
};
125126
#endif
126127

128+
127129
static void rfbProcessClientProtocolVersion(rfbClientPtr cl);
128130
static void rfbProcessClientNormalMessage(rfbClientPtr cl);
129131
static void rfbProcessClientInitMessage(rfbClientPtr cl);
@@ -134,6 +136,7 @@ static rfbMulticastFramebufferUpdateMsg* rfbPutMulticastHeader(rfbClientPtr cl,
134136
rfbBool save);
135137
static int rfbPutMulticastRectEncodingPreferred(rfbClientPtr cl, int x, int y, int w, int h, rfbBool save);
136138

139+
#define MULTICAST_FLAG_BUFFER_DIRTY 11
137140

138141
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
139142
void rfbIncrClientRef(rfbClientPtr cl)
@@ -625,7 +628,7 @@ rfbClientConnectionGone(rfbClientPtr cl)
625628

626629
if(someclient == NULL) { /* no other one has this */
627630
free(cl->multicastUpdPendingPtr);
628-
partUpdRgnBufDestroy(cl->multicastPartUpdRgnBuf);
631+
ghpringbuf_destroy(cl->multicastPartUpdRgnBuf);
629632
free(cl->multicastWholeUpdId);
630633
free(cl->multicastPartialUpdId);
631634
}
@@ -2619,7 +2622,7 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
26192622

26202623
case rfbMulticastFramebufferUpdateNACK:
26212624
{
2622-
partUpdRgnBuf* buf = (partUpdRgnBuf*)cl->multicastPartUpdRgnBuf;
2625+
ghpringbuf* buf = (ghpringbuf*)cl->multicastPartUpdRgnBuf;
26232626
uint32_t firstInBuf;
26242627

26252628
/* maybe this client sent a NACK without having registered for MulticastVNC? */
@@ -2650,22 +2653,24 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
26502653
sz_rfbMulticastFramebufferUpdateNACKMsg);
26512654

26522655
LOCK(cl->screen->multicastSharedMutex);
2653-
firstInBuf = partUpdRgnBufAt(buf, 0)->idPartial;
2656+
2657+
firstInBuf = ((partialUpdRegion*)ghpringbuf_at(buf, 0))->idPartial;
2658+
26542659
/* check if this partial update is in the buffer */
2655-
if(msg.mfun.idPartialUpd >= firstInBuf && msg.mfun.idPartialUpd < firstInBuf + partUpdRgnBufCount(buf)) {
2660+
if(msg.mfun.idPartialUpd >= firstInBuf && msg.mfun.idPartialUpd < firstInBuf + ghpringbuf_count(buf)) {
26562661
uint32_t start = msg.mfun.idPartialUpd - firstInBuf;
26572662
uint32_t i;
26582663
uint32_t significantNACKsInPast = 0;
26592664

2660-
for(i = start; i < start+msg.mfun.nPartialUpds && i < buf->len; ++i) {
2665+
for(i = start; i < start+msg.mfun.nPartialUpds && i < buf->capacity; ++i) {
26612666
#ifdef MULTICAST_DEBUG
26622667
rfbLog("MulticastVNC DEBUG: marking buffer position %u, partial id %u as NACKed\n",
26632668
i, partUpdRgnBufAt(buf, i)->idPartial);
26642669
rfbLog(" its sendrate was %d, was decreased %d\n",
26652670
partUpdRgnBufAt(buf, i)->sendrate, partUpdRgnBufAt(buf, i)->sendrate_decreased);
26662671
#endif
26672672
/* mark the lost partial updates as requested */
2668-
partUpdRgnBufAt(buf, i)->pending = TRUE;
2673+
((partialUpdRegion*)ghpringbuf_at(buf, i))->pending = TRUE;
26692674

26702675

26712676
/* this NACK CANNOT be part of a 'tightly packed' burst of sufficient size,
@@ -2674,7 +2679,7 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
26742679
if(msg.mfun.nPartialUpds < MULTICAST_MAXSENDRATE_NACKS_REQUIRED) {
26752680
uint32_t lookback = 2 * MULTICAST_MAXSENDRATE_NACKS_REQUIRED;
26762681
while(lookback) {
2677-
partialUpdRegion* p = partUpdRgnBufAt(buf, i - lookback);
2682+
partialUpdRegion* p = ((partialUpdRegion*)ghpringbuf_at(buf, i - lookback));
26782683
if(p
26792684
&& p->pending
26802685
&& !p->sendrate_decreased
@@ -2688,8 +2693,8 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
26882693
if(!cl->screen->multicastMaxSendRateFixed
26892694
&& ( msg.mfun.nPartialUpds >= MULTICAST_MAXSENDRATE_NACKS_REQUIRED /* this NACK belongs to a 'packed' burst of required size */
26902695
|| significantNACKsInPast+1 >= MULTICAST_MAXSENDRATE_NACKS_REQUIRED ) /* this NACK belongs to a 'sparse' burst of required size */
2691-
&& !partUpdRgnBufAt(buf, i)->sendrate_decreased
2692-
&& cl->screen->multicastMaxSendRate >= partUpdRgnBufAt(buf, i)->sendrate) {
2696+
&& ! ((partialUpdRegion*)ghpringbuf_at(buf, i))->sendrate_decreased
2697+
&& cl->screen->multicastMaxSendRate >= ((partialUpdRegion*)ghpringbuf_at(buf, i))->sendrate) {
26932698
uint32_t j;
26942699
#ifdef MULTICAST_DEBUG
26952700
uint32_t oldrate = cl->screen->multicastMaxSendRate;
@@ -2710,14 +2715,14 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
27102715
cl->screen->multicastMaxSendRateIncrement);
27112716
#endif
27122717
/* mark this sendrate as decreased */
2713-
for(j=0; j < partUpdRgnBufCount(buf); ++j)
2714-
if(partUpdRgnBufAt(buf, j)->sendrate == partUpdRgnBufAt(buf, i)->sendrate)
2715-
partUpdRgnBufAt(buf, j)->sendrate_decreased = TRUE;
2718+
for(j=0; j < ghpringbuf_count(buf); ++j)
2719+
if(((partialUpdRegion*)ghpringbuf_at(buf, j))->sendrate == ((partialUpdRegion*)ghpringbuf_at(buf, i))->sendrate)
2720+
((partialUpdRegion*)ghpringbuf_at(buf, j))->sendrate_decreased = TRUE;
27162721
}
27172722
}
27182723

27192724
/* mark this pixelformat and encoding as needing repair */
2720-
buf->dirty = TRUE;
2725+
buf->flags = MULTICAST_FLAG_BUFFER_DIRTY;
27212726
}
27222727
else
27232728
rfbLog("MulticastVNC: partial update %d NACKed by client %s not in sent buffer! Increasing sent buffer size helps.\n",
@@ -3184,7 +3189,7 @@ rfbSendFramebufferUpdate(rfbClientPtr cl,
31843189

31853190
if(someclient == NULL) { /* no other one has this */
31863191
free(cl->multicastUpdPendingPtr);
3187-
partUpdRgnBufDestroy(cl->multicastPartUpdRgnBuf);
3192+
ghpringbuf_destroy(cl->multicastPartUpdRgnBuf);
31883193
free(cl->multicastWholeUpdId);
31893194
free(cl->multicastPartialUpdId);
31903195
}
@@ -3208,7 +3213,10 @@ rfbSendFramebufferUpdate(rfbClientPtr cl,
32083213

32093214
if(someclient == NULL) { /* no other client has this, alloc new ones on the heap */
32103215
cl->multicastUpdPendingPtr = calloc(sizeof(rfbBool), 1);
3211-
cl->multicastPartUpdRgnBuf = partUpdRgnBufCreate(MULTICAST_PART_UPD_RGN_BUF_SIZE/cl->screen->multicastPacketSize);
3216+
cl->multicastPartUpdRgnBuf = ghpringbuf_create(MULTICAST_PART_UPD_RGN_BUF_SIZE/cl->screen->multicastPacketSize,
3217+
sizeof(partialUpdRegion),
3218+
1,
3219+
clean_partialUpdRegion);
32123220
cl->multicastWholeUpdId = calloc(sizeof(uint16_t), 1);
32133221
cl->multicastPartialUpdId = calloc(sizeof(uint32_t), 1);
32143222
rfbLog("MulticastVNC encountered new pixelformat and/or encoding, allocating new data for client %s\n", cl->host);
@@ -3883,18 +3891,18 @@ rfbSendMulticastFramebufferUpdate(rfbClientPtr cl,
38833891
rfbBool
38843892
rfbSendMulticastRepairUpdate(rfbClientPtr cl)
38853893
{
3886-
partUpdRgnBuf* buf;
3894+
ghpringbuf* buf;
38873895
rfbBool repairPending;
38883896

38893897
LOCK(cl->screen->multicastUpdateMutex);
38903898

3891-
buf = (partUpdRgnBuf*)cl->multicastPartUpdRgnBuf;
3899+
buf = (ghpringbuf*)cl->multicastPartUpdRgnBuf;
38923900
LOCK(cl->screen->multicastSharedMutex);
3893-
repairPending = buf->dirty;
3901+
repairPending = buf->flags == MULTICAST_FLAG_BUFFER_DIRTY;
38943902
UNLOCK(cl->screen->multicastSharedMutex);
38953903

38963904
if(repairPending) {
3897-
size_t i, count = partUpdRgnBufCount(buf); /* multicastUpdateMutex above ensures the buffer size isn't modified by other threads */
3905+
size_t i, count = ghpringbuf_count(buf); /* multicastUpdateMutex above ensures the buffer size isn't modified by other threads */
38983906

38993907
/* flush buffer just for safety */
39003908
if(!rfbSendMulticastUpdateBuf(cl->screen)) {
@@ -3903,7 +3911,7 @@ rfbSendMulticastRepairUpdate(rfbClientPtr cl)
39033911
}
39043912

39053913
for(i = 0; i < count; ++i) {
3906-
partialUpdRegion* pur = partUpdRgnBufAt(buf, i);
3914+
partialUpdRegion* pur = (partialUpdRegion*)ghpringbuf_at(buf, i);
39073915
if(pur->pending) {
39083916
sraRectangleIterator* i=NULL;
39093917
sraRect rect;
@@ -3938,7 +3946,7 @@ rfbSendMulticastRepairUpdate(rfbClientPtr cl)
39383946

39393947
/* mark this pixelformat and encoding combination as done */
39403948
LOCK(cl->screen->multicastSharedMutex);
3941-
buf->dirty = FALSE;
3949+
buf->flags = 0; /* unset dirty flag */
39423950
UNLOCK(cl->screen->multicastSharedMutex);
39433951
}
39443952

@@ -3957,15 +3965,15 @@ rfbPutMulticastHeader(rfbClientPtr cl, uint16_t idWholeUpd, uint32_t idPartialUp
39573965
{
39583966
if(save) {
39593967
LOCK(cl->screen->multicastSharedMutex);
3960-
partUpdRgnBuf* buf = (partUpdRgnBuf*)cl->multicastPartUpdRgnBuf;
3968+
ghpringbuf* buf = (ghpringbuf*)cl->multicastPartUpdRgnBuf;
39613969
partialUpdRegion tmp;
39623970
tmp.idWhole = idWholeUpd;
39633971
tmp.idPartial = idPartialUpd;
39643972
tmp.region = sraRgnCreate();
39653973
tmp.pending = FALSE;
39663974
tmp.sendrate = cl->screen->multicastMaxSendRate;
39673975
tmp.sendrate_decreased = FALSE;
3968-
partUpdRgnBufInsert(buf, tmp);
3976+
ghpringbuf_put(buf, &tmp);
39693977
UNLOCK(cl->screen->multicastSharedMutex);
39703978
}
39713979

@@ -4000,9 +4008,9 @@ rfbPutMulticastRectEncodingPreferred(rfbClientPtr cl, int x, int y, int w, int h
40004008
{
40014009
if(save) {
40024010
LOCK(cl->screen->multicastSharedMutex);
4003-
partUpdRgnBuf* buf = (partUpdRgnBuf*)cl->multicastPartUpdRgnBuf;
4011+
ghpringbuf* buf = (ghpringbuf*)cl->multicastPartUpdRgnBuf;
40044012
sraRegionPtr tmp = sraRgnCreateRect(x, y, x+w, y+h);
4005-
partialUpdRegion* lastone = partUpdRgnBufAt(buf, partUpdRgnBufCount(buf)-1);
4013+
partialUpdRegion* lastone = (partialUpdRegion*)ghpringbuf_at(buf, ghpringbuf_count(buf)-1);
40064014
sraRgnOr(lastone->region, tmp);
40074015
sraRgnDestroy(tmp);
40084016
UNLOCK(cl->screen->multicastSharedMutex);

0 commit comments

Comments
 (0)
Please sign in to comment.