From 7afb3af61457480e6b5deb57dae2456d9aceedc3 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 30 Dec 2018 21:08:54 +0100 Subject: [PATCH] Fake succeed all writes on closed socket (fix memory leak) --- src/AsyncSocket.h | 6 ++++++ src/WebSocketContext.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/AsyncSocket.h b/src/AsyncSocket.h index 84692be..5b65b82 100644 --- a/src/AsyncSocket.h +++ b/src/AsyncSocket.h @@ -101,6 +101,12 @@ protected: * Returns pair of bytes written (anywhere) and wheter or not this call resulted in the polling for * writable (or we are in a state that implies polling for writable). */ std::pair write(const char *src, int length, bool optionally = false, int nextLength = 0) { + /* Fake success if closed, simpel fix to allow uncork of closed socket to succeed */ + if (us_socket_is_closed((us_socket *) this)) { + std::cout << "Faking successful send due to closed socket!" << std::endl; + return {length, false}; + } + LoopData *loopData = getLoopData(); AsyncSocketData *asyncSocketData = (AsyncSocketData *) getExt(); diff --git a/src/WebSocketContext.h b/src/WebSocketContext.h index eb2cf55..9b9368e 100644 --- a/src/WebSocketContext.h +++ b/src/WebSocketContext.h @@ -263,6 +263,11 @@ private: // todo: check for failures here just like for HTTP webSocket->uncork(); + // cannot do anything else if closed + if (us_socket_is_closed((us_socket *) s)) { + return s; + } + // I guess we need to check drain here - emit drain if we had to poll for writable // are we shutdown? can onnly call this if we did succeed uncork!