Skip to content

Commit 0e2a0d2

Browse files
author
Volodymyr Samokhatko
committed
libvncserver/sockets: cork
1 parent cce08f3 commit 0e2a0d2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/libvncserver/sockets.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
/*
23+
* Copyright (C) 2012-2020, 2022-2023 D. R. Commander
2324
* Copyright (C) 2011-2012 Christian Beier <[email protected]>
2425
* Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
2526
* OSXvnc Copyright (C) 2001 Dan McGuirk <[email protected]>.
@@ -333,6 +334,52 @@ void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen)
333334
#endif
334335
}
335336

337+
/*
338+
* rfbCorkSock enables the TCP cork functionality on Linux to inform the TCP
339+
* layer to send only complete packets
340+
*/
341+
342+
void rfbCorkSock(int sock)
343+
{
344+
static int alreadywarned = 0;
345+
#ifdef TCP_CORK
346+
int one = 1;
347+
348+
if (setsockopt(sock, IPPROTO_TCP, TCP_CORK, (char *)&one, sizeof(one)) < 0) {
349+
if (!alreadywarned) {
350+
rfbLogPerror("Could not enable TCP corking");
351+
alreadywarned = 1;
352+
}
353+
}
354+
#else
355+
if (!alreadywarned) {
356+
rfbLogPerror("TCP corking not available on this system.");
357+
alreadywarned = 1;
358+
}
359+
#endif
360+
}
361+
362+
363+
/*
364+
* rfbUncorkSock disables corking and sends all partially-complete packets
365+
*/
366+
367+
void rfbUncorkSock(int sock)
368+
{
369+
#ifdef TCP_CORK
370+
static int alreadywarned = 0;
371+
int zero = 0;
372+
373+
if (setsockopt(sock, IPPROTO_TCP, TCP_CORK, (char *)&zero,
374+
sizeof(zero)) < 0) {
375+
if (!alreadywarned) {
376+
rfbLogPerror("Could not disable TCP corking");
377+
alreadywarned = 1;
378+
}
379+
}
380+
#endif
381+
}
382+
336383
/*
337384
* rfbCheckFds is called from ProcessInputEvents to check for input on the RFB
338385
* socket(s). If there is input to process, the appropriate function in the

0 commit comments

Comments
 (0)