diff --git a/base/application.cpp b/base/application.cpp index ec3970577..16dba4575 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -59,7 +59,7 @@ void Application::RunEventLoop(void) FD_ZERO(&writefds); FD_ZERO(&exceptfds); - for (list::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) { + for (Socket::CollectionType::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) { Socket::Ptr socket = i->lock(); if (socket == NULL) @@ -104,7 +104,7 @@ void Application::RunEventLoop(void) EventArgs ea; ea.Source = shared_from_this(); - list::iterator prev, i; + Socket::CollectionType::iterator prev, i; for (i = Socket::Sockets.begin(); i != Socket::Sockets.end(); ) { prev = i; i++; diff --git a/base/i2-base.h b/base/i2-base.h index c0f586a70..a07cbc54e 100644 --- a/base/i2-base.h +++ b/base/i2-base.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/base/socket.cpp b/base/socket.cpp index 394f8380b..4e5a2f00f 100644 --- a/base/socket.cpp +++ b/base/socket.cpp @@ -2,7 +2,7 @@ using namespace icinga; -list Socket::Sockets; +Socket::CollectionType Socket::Sockets; Socket::Socket(void) { @@ -20,12 +20,16 @@ void Socket::Start(void) OnException += bind_weak(&Socket::ExceptionEventHandler, shared_from_this()); - Sockets.push_front(static_pointer_cast(shared_from_this())); + Sockets.insert(static_pointer_cast(shared_from_this())); } void Socket::Stop(void) { - Sockets.remove_if(weak_ptr_eq_raw(this)); + Socket::Ptr self = static_pointer_cast(shared_from_this()); + Socket::CollectionType::iterator i = Sockets.find(self); + + if (i != Sockets.end()) + Sockets.erase(i); } void Socket::SetFD(SOCKET fd) @@ -112,7 +116,7 @@ int Socket::ExceptionEventHandler(const EventArgs& ea) void Socket::CloseAllSockets(void) { - for (list::iterator i = Sockets.begin(); i != Sockets.end(); ) { + for (Socket::CollectionType::iterator i = Sockets.begin(); i != Sockets.end(); ) { Socket::Ptr socket = i->lock(); i++; diff --git a/base/socket.h b/base/socket.h index 90ac7a266..1e8d4ff2d 100644 --- a/base/socket.h +++ b/base/socket.h @@ -31,7 +31,9 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - static list Sockets; + typedef set< Socket::WeakPtr, owner_less > CollectionType; + + static Socket::CollectionType Sockets; ~Socket(void); diff --git a/base/tcpserver.cpp b/base/tcpserver.cpp index a96a2f06f..b4b7f7b70 100644 --- a/base/tcpserver.cpp +++ b/base/tcpserver.cpp @@ -32,8 +32,6 @@ void TCPServer::Listen(void) Close(); return; } - - Start(); } int TCPServer::ReadableEventHandler(const EventArgs& ea) @@ -45,13 +43,6 @@ int TCPServer::ReadableEventHandler(const EventArgs& ea) fd = accept(GetFD(), (sockaddr *)&addr, &addrlen); if (fd == INVALID_SOCKET) { -#ifdef _WIN32 - if (WSAGetLastError() == WSAEWOULDBLOCK) -#else /* _WIN32 */ - if (errno == EINPROGRESS) -#endif /* _WIN32 */ - return 0; - SocketErrorEventArgs sea; #ifdef _WIN32 sea.Code = WSAGetLastError(); diff --git a/base/timer.cpp b/base/timer.cpp index 73c7ff2aa..1e28bab7b 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -5,7 +5,7 @@ using namespace icinga; time_t Timer::NextCall; -list Timer::Timers; +Timer::CollectionType Timer::Timers; Timer::Timer(void) { @@ -25,7 +25,7 @@ void Timer::RescheduleTimers(void) /* Make sure we wake up at least once every 30 seconds */ NextCall = time(NULL) + 30; - for (list::iterator i = Timers.begin(); i != Timers.end(); i++) { + for (Timer::CollectionType::iterator i = Timers.begin(); i != Timers.end(); i++) { Timer::Ptr timer = i->lock(); if (timer == NULL) @@ -42,7 +42,7 @@ void Timer::CallExpiredTimers(void) time(&now); - for (list::iterator i = Timers.begin(); i != Timers.end(); ) { + for (Timer::CollectionType::iterator i = Timers.begin(); i != Timers.end(); ) { Timer::Ptr timer = Timer::Ptr(*i); i++; @@ -58,7 +58,7 @@ void Timer::CallExpiredTimers(void) void Timer::StopAllTimers(void) { - for (list::iterator i = Timers.begin(); i != Timers.end(); ) { + for (Timer::CollectionType::iterator i = Timers.begin(); i != Timers.end(); ) { Timer::Ptr timer = i->lock(); i++; @@ -103,16 +103,18 @@ EventArgs Timer::GetUserArgs(void) const void Timer::Start(void) { - Stop(); - - Timers.push_front(static_pointer_cast(shared_from_this())); + Timers.insert(static_pointer_cast(shared_from_this())); Reschedule(time(NULL) + m_Interval); } void Timer::Stop(void) { - Timers.remove_if(weak_ptr_eq_raw(this)); + Timer::Ptr self = static_pointer_cast(shared_from_this()); + Timer::CollectionType::iterator i = Timers.find(self); + + if (i != Timers.end()) + Timers.erase(i); } void Timer::Reschedule(time_t next) diff --git a/base/timer.h b/base/timer.h index 3e8c7c555..22ee8c53d 100644 --- a/base/timer.h +++ b/base/timer.h @@ -30,7 +30,9 @@ public: typedef shared_ptr Ptr; typedef weak_ptr WeakPtr; - static list Timers; + typedef set< Timer::WeakPtr, owner_less > CollectionType; + + static Timer::CollectionType Timers; Timer(void); diff --git a/icinga/virtualendpoint.cpp b/icinga/virtualendpoint.cpp index 15ce559b0..f1a203d27 100644 --- a/icinga/virtualendpoint.cpp +++ b/icinga/virtualendpoint.cpp @@ -32,7 +32,7 @@ void VirtualEndpoint::ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& map >::iterator i = m_MethodHandlers.find(method); if (i == m_MethodHandlers.end()) - throw InvalidArgumentException(); + return; NewRequestEventArgs nrea; nrea.Source = shared_from_this();