From c5b7137f2b1170cddf79bd79d39224aee4aba7d5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 18 May 2020 19:40:49 +0200 Subject: [PATCH] Flush data on close There might be some final handshake data that is still stuck in the buffers, so make a best effort attempt at getting it to the client. --- common/rfb/VNCSConnectionST.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index 31bd16e..9e7f3de 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -155,6 +155,17 @@ void VNCSConnectionST::close(const char* reason) server->lastDisconnectTime = time(0); } + try { + if (sock->outStream().bufferUsage() > 0) { + sock->cork(false); + sock->outStream().flush(); + if (sock->outStream().bufferUsage() > 0) + vlog.error("Failed to flush remaining socket data on close"); + } + } catch (rdr::Exception& e) { + vlog.error("Failed to flush remaining socket data on close: %s", e.str()); + } + // Just shutdown the socket and mark our state as closing. Eventually the // calling code will call VNCServerST's removeSocket() method causing us to // be deleted.