Merge pull request #6479 from Icinga/feature/socketevents-inherit-object-6477

SocketEvents: inherit from Stream
This commit is contained in:
Michael Friedrich 2018-11-12 17:06:37 +01:00 committed by GitHub
commit 90de216cbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 23 deletions

View File

@ -113,8 +113,6 @@ void SocketEventEngineEpoll::ThreadProc(int tid)
EventDescription event; EventDescription event;
event.REvents = SocketEventEngineEpoll::EpollToPoll(pevents[i].events); event.REvents = SocketEventEngineEpoll::EpollToPoll(pevents[i].events);
event.Descriptor = m_Sockets[tid][pevents[i].data.fd]; event.Descriptor = m_Sockets[tid][pevents[i].data.fd];
event.LifesupportReference = event.Descriptor.LifesupportObject;
VERIFY(event.LifesupportReference);
events.emplace_back(std::move(event)); 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; int tid = se->m_ID % SOCKET_IOTHREADS;
@ -145,7 +143,6 @@ void SocketEventEngineEpoll::Register(SocketEvents *se, Object *lifesupportObjec
SocketEventDescriptor desc; SocketEventDescriptor desc;
desc.EventInterface = se; desc.EventInterface = se;
desc.LifesupportObject = lifesupportObject;
VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end()); VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end());

View File

@ -111,8 +111,6 @@ void SocketEventEnginePoll::ThreadProc(int tid)
EventDescription event; EventDescription event;
event.REvents = pfds[i].revents; event.REvents = pfds[i].revents;
event.Descriptor = descriptors[i]; event.Descriptor = descriptors[i];
event.LifesupportReference = event.Descriptor.LifesupportObject;
VERIFY(event.LifesupportReference);
events.emplace_back(std::move(event)); 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; int tid = se->m_ID % SOCKET_IOTHREADS;
@ -144,7 +142,6 @@ void SocketEventEnginePoll::Register(SocketEvents *se, Object *lifesupportObject
SocketEventDescriptor desc; SocketEventDescriptor desc;
desc.Events = 0; desc.Events = 0;
desc.EventInterface = se; desc.EventInterface = se;
desc.LifesupportObject = lifesupportObject;
VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end()); VERIFY(m_Sockets[tid].find(se->m_FD) == m_Sockets[tid].end());

View File

@ -111,12 +111,12 @@ void SocketEvents::InitializeEngine()
/** /**
* Constructor for the SocketEvents class. * 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) : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(nullptr)
{ {
boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeEngine); boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeEngine);
Register(lifesupportObject); Register();
} }
SocketEvents::~SocketEvents() SocketEvents::~SocketEvents()
@ -124,9 +124,9 @@ SocketEvents::~SocketEvents()
VERIFY(m_FD == INVALID_SOCKET); 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() void SocketEvents::Unregister()

View File

@ -22,6 +22,7 @@
#include "base/i2-base.hpp" #include "base/i2-base.hpp"
#include "base/socket.hpp" #include "base/socket.hpp"
#include "base/stream.hpp"
#include <boost/thread/condition_variable.hpp> #include <boost/thread/condition_variable.hpp>
#include <thread> #include <thread>
@ -37,9 +38,11 @@ namespace icinga
* *
* @ingroup base * @ingroup base
*/ */
class SocketEvents class SocketEvents : public Stream
{ {
public: public:
DECLARE_PTR_TYPEDEFS(SocketEvents);
~SocketEvents(); ~SocketEvents();
virtual void OnEvent(int revents); virtual void OnEvent(int revents);
@ -54,7 +57,7 @@ public:
void SetEnginePrivate(void *priv); void SetEnginePrivate(void *priv);
protected: protected:
SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject); SocketEvents(const Socket::Ptr& socket);
private: private:
int m_ID; int m_ID;
@ -68,7 +71,7 @@ private:
void WakeUpThread(bool wait = false); void WakeUpThread(bool wait = false);
void Register(Object *lifesupportObject); void Register();
friend class SocketEventEnginePoll; friend class SocketEventEnginePoll;
friend class SocketEventEngineEpoll; friend class SocketEventEngineEpoll;
@ -79,15 +82,13 @@ private:
struct SocketEventDescriptor struct SocketEventDescriptor
{ {
int Events{POLLIN}; int Events{POLLIN};
SocketEvents *EventInterface{nullptr}; SocketEvents::Ptr EventInterface;
Object *LifesupportObject{nullptr};
}; };
struct EventDescription struct EventDescription
{ {
int REvents; int REvents;
SocketEventDescriptor Descriptor; SocketEventDescriptor Descriptor;
Object::Ptr LifesupportReference;
}; };
class SocketEventEngine class SocketEventEngine
@ -102,7 +103,7 @@ public:
protected: protected:
virtual void InitializeThread(int tid) = 0; virtual void InitializeThread(int tid) = 0;
virtual void ThreadProc(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 Unregister(SocketEvents *se) = 0;
virtual void ChangeEvents(SocketEvents *se, int events) = 0; virtual void ChangeEvents(SocketEvents *se, int events) = 0;
@ -119,7 +120,7 @@ protected:
class SocketEventEnginePoll final : public SocketEventEngine class SocketEventEnginePoll final : public SocketEventEngine
{ {
public: public:
void Register(SocketEvents *se, Object *lifesupportObject) override; void Register(SocketEvents *se) override;
void Unregister(SocketEvents *se) override; void Unregister(SocketEvents *se) override;
void ChangeEvents(SocketEvents *se, int events) override; void ChangeEvents(SocketEvents *se, int events) override;
@ -132,7 +133,7 @@ protected:
class SocketEventEngineEpoll : public SocketEventEngine class SocketEventEngineEpoll : public SocketEventEngine
{ {
public: public:
virtual void Register(SocketEvents *se, Object *lifesupportObject); virtual void Register(SocketEvents *se);
virtual void Unregister(SocketEvents *se); virtual void Unregister(SocketEvents *se);
virtual void ChangeEvents(SocketEvents *se, int events); virtual void ChangeEvents(SocketEvents *se, int events);

View File

@ -43,7 +43,7 @@ bool TlsStream::m_SSLIndexInitialized = false;
* @param sslContext The SSL context for the client. * @param sslContext The SSL context for the client.
*/ */
TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const std::shared_ptr<SSL_CTX>& sslContext) TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, ConnectionRole role, const std::shared_ptr<SSL_CTX>& 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_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) m_CurrentAction(TlsActionNone), m_Retry(false), m_Shutdown(false)
{ {

View File

@ -43,7 +43,7 @@ enum TlsAction
* *
* @ingroup base * @ingroup base
*/ */
class TlsStream final : public Stream, private SocketEvents class TlsStream final : public SocketEvents
{ {
public: public:
DECLARE_PTR_TYPEDEFS(TlsStream); DECLARE_PTR_TYPEDEFS(TlsStream);