From c0f946f2b7195e101cdaae9d5453e0027d4204b4 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Mon, 9 Sep 2013 13:30:31 +0200 Subject: m_httpd Close all open http sockets on unload --- src/modules/m_httpd.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 37f715a8d..6315809a9 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -32,6 +32,7 @@ class ModuleHttpServer; static ModuleHttpServer* HttpModule; static bool claimed; +static std::set sockets; /** HTTP socket states */ @@ -69,6 +70,11 @@ class HttpServerSocket : public BufferedSocket GetIOHook()->OnStreamSocketAccept(this, client, server); } + ~HttpServerSocket() + { + sockets.erase(this); + } + virtual void OnError(BufferedSocketError) { ServerInstance->GlobalCulls.AddItem(this); @@ -333,7 +339,6 @@ class HttpServerSocket : public BufferedSocket class ModuleHttpServer : public Module { - std::vector httpsocks; public: void init() @@ -358,18 +363,21 @@ class ModuleHttpServer : public Module int port; std::string incomingip; irc::sockets::satoap(*client, incomingip, port); - new HttpServerSocket(nfd, incomingip, from, client, server); + sockets.insert(new HttpServerSocket(nfd, incomingip, from, client, server)); return MOD_RES_ALLOW; } - - virtual ~ModuleHttpServer() + CullResult cull() { - for (size_t i = 0; i < httpsocks.size(); i++) + std::set local; + local.swap(sockets); + for (std::set::const_iterator i = local.begin(); i != local.end(); ++i) { - httpsocks[i]->cull(); - delete httpsocks[i]; + HttpServerSocket* sock = *i; + sock->cull(); + delete sock; } + return Module::cull(); } virtual Version GetVersion() -- cgit v1.2.3