From f3d80041f68417cc10d8e7575659468b30009f22 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 3 Nov 2014 15:42:08 +0100 Subject: m_flashpolicyd, m_httpd Handle timeouts using the Timer system --- src/modules/m_flashpolicyd.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/modules/m_flashpolicyd.cpp') diff --git a/src/modules/m_flashpolicyd.cpp b/src/modules/m_flashpolicyd.cpp index 46fd33e61..6466a9fb2 100644 --- a/src/modules/m_flashpolicyd.cpp +++ b/src/modules/m_flashpolicyd.cpp @@ -28,15 +28,25 @@ namespace const std::string expected_request("\0", 23); } -class FlashPDSocket : public BufferedSocket +class FlashPDSocket : public BufferedSocket, public Timer { - public: - time_t created; + /** True if this object is in the cull list + */ + bool waitingcull; - FlashPDSocket(int newfd) + bool Tick(time_t currtime) CXX11_OVERRIDE + { + AddToCull(); + return false; + } + + public: + FlashPDSocket(int newfd, unsigned int timeoutsec) : BufferedSocket(newfd) - , created(ServerInstance->Time()) + , Timer(timeoutsec) + , waitingcull(false) { + ServerInstance->Timers.AddTimer(this); } ~FlashPDSocket() @@ -58,10 +68,10 @@ class FlashPDSocket : public BufferedSocket void AddToCull() { - if (created == 0) + if (waitingcull) return; - created = 0; + waitingcull = true; Close(); ServerInstance->GlobalCulls.AddItem(this); } @@ -69,19 +79,9 @@ class FlashPDSocket : public BufferedSocket class ModuleFlashPD : public Module { - time_t timeout; + unsigned int timeout; public: - void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE - { - for (std::set::const_iterator i = sockets.begin(); i != sockets.end(); ++i) - { - FlashPDSocket* sock = *i; - if ((sock->created + timeout <= curtime) && (sock->created != 0)) - sock->AddToCull(); - } - } - ModResult OnAcceptConnection(int nfd, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE { if (from->bind_tag->getString("type") != "flashpolicyd") @@ -90,7 +90,7 @@ class ModuleFlashPD : public Module if (policy_reply.empty()) return MOD_RES_DENY; - sockets.insert(new FlashPDSocket(nfd)); + sockets.insert(new FlashPDSocket(nfd, timeout)); return MOD_RES_ALLOW; } -- cgit v1.2.3 From ce3ce6cd49e14f640a1cabfef9cf21a239dd961d Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 3 Nov 2014 15:43:49 +0100 Subject: m_flashpolicyd, m_httpd Store sockets in a intrusive list --- src/modules/m_flashpolicyd.cpp | 8 ++++---- src/modules/m_httpd.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/modules/m_flashpolicyd.cpp') diff --git a/src/modules/m_flashpolicyd.cpp b/src/modules/m_flashpolicyd.cpp index 6466a9fb2..8f847e111 100644 --- a/src/modules/m_flashpolicyd.cpp +++ b/src/modules/m_flashpolicyd.cpp @@ -23,12 +23,12 @@ class FlashPDSocket; namespace { - std::set sockets; + insp::intrusive_list sockets; std::string policy_reply; const std::string expected_request("\0", 23); } -class FlashPDSocket : public BufferedSocket, public Timer +class FlashPDSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node { /** True if this object is in the cull list */ @@ -90,7 +90,7 @@ class ModuleFlashPD : public Module if (policy_reply.empty()) return MOD_RES_DENY; - sockets.insert(new FlashPDSocket(nfd, timeout)); + sockets.push_front(new FlashPDSocket(nfd, timeout)); return MOD_RES_ALLOW; } @@ -148,7 +148,7 @@ class ModuleFlashPD : public Module CullResult cull() { - for (std::set::const_iterator i = sockets.begin(); i != sockets.end(); ++i) + for (insp::intrusive_list::const_iterator i = sockets.begin(); i != sockets.end(); ++i) { FlashPDSocket* sock = *i; sock->AddToCull(); diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 30612f644..a4452c9c0 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -30,7 +30,7 @@ class ModuleHttpServer; static ModuleHttpServer* HttpModule; static bool claimed; -static std::set sockets; +static insp::intrusive_list sockets; /** HTTP socket states */ @@ -43,7 +43,7 @@ enum HttpState /** A socket used for HTTP transport */ -class HttpServerSocket : public BufferedSocket, public Timer +class HttpServerSocket : public BufferedSocket, public Timer, public insp::intrusive_list_node { HttpState InternalState; std::string ip; @@ -397,13 +397,13 @@ class ModuleHttpServer : public Module int port; std::string incomingip; irc::sockets::satoap(*client, incomingip, port); - sockets.insert(new HttpServerSocket(nfd, incomingip, from, client, server, timeoutsec)); + sockets.push_front(new HttpServerSocket(nfd, incomingip, from, client, server, timeoutsec)); return MOD_RES_ALLOW; } CullResult cull() CXX11_OVERRIDE { - for (std::set::const_iterator i = sockets.begin(); i != sockets.end(); ++i) + for (insp::intrusive_list::const_iterator i = sockets.begin(); i != sockets.end(); ++i) { HttpServerSocket* sock = *i; sock->AddToCull(); -- cgit v1.2.3