aboutsummaryrefslogtreecommitdiffstats
path: root/common/network/Socket.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/network/Socket.cxx')
-rw-r--r--common/network/Socket.cxx15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx
index 0a35e267..49abbc84 100644
--- a/common/network/Socket.cxx
+++ b/common/network/Socket.cxx
@@ -43,8 +43,12 @@
#include <network/Socket.h>
+#include <rfb/LogWriter.h>
+
using namespace network;
+static rfb::LogWriter vlog("Socket");
+
// -=- Socket initialisation
static bool socketsInitialised = false;
void network::initSockets() {
@@ -98,6 +102,17 @@ Socket::~Socket()
// if shutdown() is overridden then the override MUST call on to here
void Socket::shutdown()
{
+ try {
+ if (outstream->hasBufferedData()) {
+ outstream->cork(false);
+ outstream->flush();
+ if (outstream->hasBufferedData())
+ vlog.error("Failed to flush remaining socket data on close");
+ }
+ } catch (std::exception& e) {
+ vlog.error("Failed to flush remaining socket data on close: %s", e.what());
+ }
+
isShutdown_ = true;
::shutdown(getFd(), SHUT_RDWR);
}