From de7011e54ad88656e01c92a88dd053a94b5acc6b Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Wed, 22 May 2019 13:47:17 -0500 Subject: Add an overload of StreamSocket::Close which closes when all data has been written. Fixes sending large pages in m_httpd (#1646).--- src/inspsocket.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/inspsocket.cpp') diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 59d9558a4..684ee051d 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -95,6 +95,10 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& void StreamSocket::Close() { + if (closing) + return; + + closing = true; if (this->fd > -1) { // final chance, dump as much of the sendq as we can @@ -114,6 +118,14 @@ void StreamSocket::Close() } } +void StreamSocket::Close(bool writeblock) +{ + if (getSendQSize() != 0 && writeblock) + closeonempty = true; + else + Close(); +} + CullResult StreamSocket::cull() { Close(); @@ -206,7 +218,12 @@ static const int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128; void StreamSocket::DoWrite() { if (getSendQSize() == 0) + { + if (closeonempty) + Close(); + return; + } if (!error.empty() || fd < 0) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DoWrite on errored or closed socket"); @@ -242,6 +259,9 @@ void StreamSocket::DoWrite() if (psendq) FlushSendQ(*psendq); + + if (getSendQSize() == 0 && closeonempty) + Close(); } void StreamSocket::FlushSendQ(SendQueue& sq) -- cgit v1.3.1-10-gc9f91