diff --git a/lib/base/socketevents-epoll.cpp b/lib/base/socketevents-epoll.cpp index ba2e7e25b..932323c6e 100644 --- a/lib/base/socketevents-epoll.cpp +++ b/lib/base/socketevents-epoll.cpp @@ -113,8 +113,6 @@ void SocketEventEngineEpoll::ThreadProc(int tid) EventDescription event; event.REvents = SocketEventEngineEpoll::EpollToPoll(pevents[i].events); event.Descriptor = m_Sockets[tid][pevents[i].data.fd]; - event.LifesupportReference = event.Descriptor.LifesupportObject; - VERIFY(event.LifesupportReference); events.emplace_back(std::move(event)); } @@ -134,7 +132,7 @@ void SocketEventEngineEpoll::ThreadProc(int tid) } } -void SocketEventEngineEpoll::Register(SocketEvents *se, Object *lifesupportObject) +void SocketEventEngineEpoll::Register(SocketEvents *se) { int tid = se->m_ID % SOCKET_IOTHREADS; @@ -145,7 +143,6 @@ void SocketEventEngineEpoll::Register(SocketEvents *se, Object *lifesupportObjec SocketEventDescriptor desc; desc.EventInterface = se; - desc.LifesupportObject = lifesupportObject; VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end()); diff --git a/lib/base/socketevents-poll.cpp b/lib/base/socketevents-poll.cpp index e46dd2c45..afb43177e 100644 --- a/lib/base/socketevents-poll.cpp +++ b/lib/base/socketevents-poll.cpp @@ -111,8 +111,6 @@ void SocketEventEnginePoll::ThreadProc(int tid) EventDescription event; event.REvents = pfds[i].revents; event.Descriptor = descriptors[i]; - event.LifesupportReference = event.Descriptor.LifesupportObject; - VERIFY(event.LifesupportReference); events.emplace_back(std::move(event)); } @@ -132,7 +130,7 @@ void SocketEventEnginePoll::ThreadProc(int tid) } } -void SocketEventEnginePoll::Register(SocketEvents *se, Object *lifesupportObject) +void SocketEventEnginePoll::Register(SocketEvents *se) { int tid = se->m_ID % SOCKET_IOTHREADS; @@ -144,7 +142,6 @@ void SocketEventEnginePoll::Register(SocketEvents *se, Object *lifesupportObject SocketEventDescriptor desc; desc.Events = 0; desc.EventInterface = se; - desc.LifesupportObject = lifesupportObject; VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end()); diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index 1400396a4..286460eab 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -111,12 +111,12 @@ void SocketEvents::InitializeEngine() /** * Constructor for the SocketEvents class. */ -SocketEvents::SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject) +SocketEvents::SocketEvents(const Socket::Ptr& socket) : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(nullptr) { boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeEngine); - Register(lifesupportObject); + Register(); } SocketEvents::~SocketEvents() @@ -124,9 +124,9 @@ SocketEvents::~SocketEvents() VERIFY(m_FD == INVALID_SOCKET); } -void SocketEvents::Register(Object *lifesupportObject) +void SocketEvents::Register() { - l_SocketIOEngine->Register(this, lifesupportObject); + l_SocketIOEngine->Register(this); } void SocketEvents::Unregister() diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index 486ec4df1..44bca3071 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -22,6 +22,7 @@ #include "base/i2-base.hpp" #include "base/socket.hpp" +#include "base/stream.hpp" #include #include @@ -37,9 +38,11 @@ namespace icinga * * @ingroup base */ -class SocketEvents +class SocketEvents : public Stream { public: + DECLARE_PTR_TYPEDEFS(SocketEvents); + ~SocketEvents(); virtual void OnEvent(int revents); @@ -54,7 +57,7 @@ public: void SetEnginePrivate(void *priv); protected: - SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject); + SocketEvents(const Socket::Ptr& socket); private: int m_ID; @@ -68,7 +71,7 @@ private: void WakeUpThread(bool wait = false); - void Register(Object *lifesupportObject); + void Register(); friend class SocketEventEnginePoll; friend class SocketEventEngineEpoll; @@ -79,15 +82,13 @@ private: struct SocketEventDescriptor { int Events{POLLIN}; - SocketEvents *EventInterface{nullptr}; - Object *LifesupportObject{nullptr}; + SocketEvents::Ptr EventInterface; }; struct EventDescription { int REvents; SocketEventDescriptor Descriptor; - Object::Ptr LifesupportReference; }; class SocketEventEngine @@ -102,7 +103,7 @@ public: protected: virtual void InitializeThread(int tid) = 0; virtual void ThreadProc(int tid) = 0; - virtual void Register(SocketEvents *se, Object *lifesupportObject) = 0; + virtual void Register(SocketEvents *se) = 0; virtual void Unregister(SocketEvents *se) = 0; virtual void ChangeEvents(SocketEvents *se, int events) = 0; @@ -119,7 +120,7 @@ protected: class SocketEventEnginePoll final : public SocketEventEngine { public: - void Register(SocketEvents *se, Object *lifesupportObject) override; + void Register(SocketEvents *se) override; void Unregister(SocketEvents *se) override; void ChangeEvents(SocketEvents *se, int events) override; @@ -132,7 +133,7 @@ protected: class SocketEventEngineEpoll : public SocketEventEngine { public: - virtual void Register(SocketEvents *se, Object *lifesupportObject); + virtual void Register(SocketEvents *se); virtual void Unregister(SocketEvents *se); virtual void ChangeEvents(SocketEvents *se, int events); diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index f57af8d5e..a694f86bf 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -43,7 +43,7 @@ bool TlsStream::m_SSLIndexInitialized = false; * @param sslContext The SSL context for the client. */ TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const std::shared_ptr& sslContext) - : SocketEvents(socket, this), m_Eof(false), m_HandshakeOK(false), m_VerifyOK(true), m_ErrorCode(0), + : SocketEvents(socket), m_Eof(false), m_HandshakeOK(false), m_VerifyOK(true), m_ErrorCode(0), m_ErrorOccurred(false), m_Socket(socket), m_Role(role), m_SendQ(new FIFO()), m_RecvQ(new FIFO()), m_CurrentAction(TlsActionNone), m_Retry(false), m_Shutdown(false) { diff --git a/lib/base/tlsstream.hpp b/lib/base/tlsstream.hpp index 8e4ceb08e..45519b5b1 100644 --- a/lib/base/tlsstream.hpp +++ b/lib/base/tlsstream.hpp @@ -43,7 +43,7 @@ enum TlsAction * * @ingroup base */ -class TlsStream final : public Stream, private SocketEvents +class TlsStream final : public SocketEvents { public: DECLARE_PTR_TYPEDEFS(TlsStream);