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/modules/m_httpd.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 8c409cbcb..dadd2f257 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -72,11 +72,17 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru /** True if this object is in the cull list */ bool waitingcull; + bool messagecomplete; bool Tick(time_t currtime) CXX11_OVERRIDE { - AddToCull(); - return false; + if (!messagecomplete) + { + AddToCull(); + return false; + } + + return true; } template @@ -186,6 +192,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru int OnMessageComplete() { + messagecomplete = true; ServeData(); return 0; } @@ -197,6 +204,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru , ip(IP) , status_code(0) , waitingcull(false) + , messagecomplete(false) { if ((!via->iohookprovs.empty()) && (via->iohookprovs.back())) { @@ -231,9 +239,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru "Server error %u: %s
" "Powered by InspIRCd", response, http_status_str((http_status)response)); - SendHeaders(data.length(), response, empty); - WriteData(data); - Close(); + Page(data, response, &empty); } void SendHeaders(unsigned long size, unsigned int response, HTTPHeaders &rheaders) @@ -286,11 +292,16 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru } } + void Page(const std::string& s, unsigned int response, HTTPHeaders* hheaders) + { + SendHeaders(s.length(), response, *hheaders); + WriteData(s); + Close(true); + } + void Page(std::stringstream* n, unsigned int response, HTTPHeaders* hheaders) { - SendHeaders(n->str().length(), response, *hheaders); - WriteData(n->str()); - Close(); + Page(n->str(), response, hheaders); } void AddToCull() -- cgit v1.2.3