Cork the outgoing TCP stream while we still have messages to process. This
allows more efficent use of the congestion window as we will send fewer packets.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4782 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx
index d73d753..bcc7f23 100644
--- a/common/rfb/VNCSConnectionST.cxx
+++ b/common/rfb/VNCSConnectionST.cxx
@@ -17,6 +17,7 @@
  * USA.
  */
 
+#include <network/TcpSocket.h>
 #include <rfb/VNCSConnectionST.h>
 #include <rfb/LogWriter.h>
 #include <rfb/Security.h>
@@ -114,10 +115,17 @@
 
     inProcessMessages = true;
 
+    // Get the underlying TCP layer to build large packets if we send
+    // multiple small responses.
+    network::TcpSocket::cork(sock->getFd(), true);
+
     while (getInStream()->checkNoWait(1)) {
       processMsg();
     }
 
+    // Flush out everything in case we go idle after this.
+    network::TcpSocket::cork(sock->getFd(), false);
+
     inProcessMessages = false;
 
     // If there were anything requiring an update, try to send it here.