From 671fba2fce9e3b0f1cb5f15ee39279751cd276d7 Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Tue, 23 Jan 2024 16:01:59 -0800 Subject: [PATCH 1/4] boostification of wssession --- src/cpp/handler/handlerengine.cpp | 23 ++++++++++------------- src/cpp/handler/wssession.cpp | 6 +++--- src/cpp/handler/wssession.h | 11 +++++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cpp/handler/handlerengine.cpp b/src/cpp/handler/handlerengine.cpp index e4294ec4..03a82b13 100644 --- a/src/cpp/handler/handlerengine.cpp +++ b/src/cpp/handler/handlerengine.cpp @@ -1256,6 +1256,9 @@ class HandlerEngine::Private : public QObject Connection connectionsRefreshedConnection; Connection unsubscribedConnection; Connection reportedConnection; + Connection sendConnection; + Connection expConnection; + Connection errorConnection; Private(HandlerEngine *_q) : QObject(_q), @@ -1597,7 +1600,6 @@ class HandlerEngine::Private : public QObject // nothing to do } -private: void handlePublishItem(const PublishItem &item) { // only sequence if someone is listening, because we @@ -2597,9 +2599,9 @@ private slots: if(!s) { s = new WsSession(this); - connect(s, &WsSession::send, this, &Private::wssession_send); - connect(s, &WsSession::expired, this, &Private::wssession_expired); - connect(s, &WsSession::error, this, &Private::wssession_error); + sendConnection = s->send.connect(boost::bind(&Private::wssession_send, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, s)); + expConnection = s->expired.connect(boost::bind(&Private::wssession_expired, this, s)); + errorConnection = s->error.connect(boost::bind(&Private::wssession_error, this, s)); s->cid = QString::fromUtf8(item.cid); s->ttl = item.ttl; s->requestData.uri = item.uri; @@ -3128,10 +3130,9 @@ private slots: writeRetryPacket(rp); } - void wssession_send(int reqId, const QByteArray &type, const QByteArray &message) +private: + void wssession_send(int reqId, const QByteArray &type, const QByteArray &message, WsSession *s) { - WsSession *s = (WsSession *)sender(); - WsControlPacket::Item i; i.cid = s->cid.toUtf8(); i.requestId = QByteArray::number(reqId); @@ -3143,17 +3144,13 @@ private slots: writeWsControlItems(QList() << i); } - void wssession_expired() + void wssession_expired(WsSession *s) { - WsSession *s = (WsSession *)sender(); - removeWsSession(s); } - void wssession_error() + void wssession_error(WsSession *s) { - WsSession *s = (WsSession *)sender(); - log_debug("ws session %s control error", qPrintable(s->cid)); WsControlPacket::Item i; diff --git a/src/cpp/handler/wssession.cpp b/src/cpp/handler/wssession.cpp index 58653bb2..0fad0eb0 100644 --- a/src/cpp/handler/wssession.cpp +++ b/src/cpp/handler/wssession.cpp @@ -122,7 +122,7 @@ void WsSession::expireTimer_timeout() { log_debug("timing out ws session: %s", qPrintable(cid)); - emit expired(); + expired(); } void WsSession::delayedTimer_timeout() @@ -135,7 +135,7 @@ void WsSession::delayedTimer_timeout() pendingRequests[reqId] = QDateTime::currentMSecsSinceEpoch() + WSCONTROL_REQUEST_TIMEOUT; setupRequestTimer(); - emit send(reqId, delayedType, message); + send(reqId, delayedType, message); } void WsSession::requestTimer_timeout() @@ -144,5 +144,5 @@ void WsSession::requestTimer_timeout() pendingRequests.clear(); setupRequestTimer(); - emit error(); + error(); } diff --git a/src/cpp/handler/wssession.h b/src/cpp/handler/wssession.h index 79d898f9..8d1c737c 100644 --- a/src/cpp/handler/wssession.h +++ b/src/cpp/handler/wssession.h @@ -27,6 +27,10 @@ #include #include #include "packet/httprequestdata.h" +#include + +using Signal = boost::signals2::signal; +using Connection = boost::signals2::scoped_connection; class QTimer; @@ -64,10 +68,9 @@ class WsSession : public QObject void sendDelayed(const QByteArray &type, const QByteArray &message, int timeout); void ack(int reqId); -signals: - void send(int reqId, const QByteArray &type, const QByteArray &message); - void expired(); - void error(); + boost::signals2::signal send; + Signal expired; + Signal error; private: void setupRequestTimer(); From b8b4cd56d575fd7481181d444972e0f727994903 Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Tue, 23 Jan 2024 16:02:44 -0800 Subject: [PATCH 2/4] fix --- src/cpp/handler/handlerengine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpp/handler/handlerengine.cpp b/src/cpp/handler/handlerengine.cpp index 03a82b13..798a8ba3 100644 --- a/src/cpp/handler/handlerengine.cpp +++ b/src/cpp/handler/handlerengine.cpp @@ -1600,6 +1600,7 @@ class HandlerEngine::Private : public QObject // nothing to do } +private: void handlePublishItem(const PublishItem &item) { // only sequence if someone is listening, because we From fa66c63ef3cb649d12ad41c2d48b52a6216568d0 Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Tue, 23 Jan 2024 16:03:06 -0800 Subject: [PATCH 3/4] fix --- src/cpp/handler/handlerengine.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpp/handler/handlerengine.cpp b/src/cpp/handler/handlerengine.cpp index 798a8ba3..7327afe3 100644 --- a/src/cpp/handler/handlerengine.cpp +++ b/src/cpp/handler/handlerengine.cpp @@ -3131,7 +3131,6 @@ private slots: writeRetryPacket(rp); } -private: void wssession_send(int reqId, const QByteArray &type, const QByteArray &message, WsSession *s) { WsControlPacket::Item i; From 14b0e09c520a69d3bba559aa64d40bb636fd2bcb Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Thu, 25 Jan 2024 11:12:33 -0800 Subject: [PATCH 4/4] comments addressed --- src/cpp/handler/handlerengine.cpp | 19 +++++++++++++------ src/cpp/handler/wssession.h | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/cpp/handler/handlerengine.cpp b/src/cpp/handler/handlerengine.cpp index 37ec4374..148346a3 100644 --- a/src/cpp/handler/handlerengine.cpp +++ b/src/cpp/handler/handlerengine.cpp @@ -87,6 +87,12 @@ using namespace VariantUtil; +struct WSSessionConnections { + Connection sendConnection; + Connection expConnection; + Connection errorConnection; +}; + static QList parseItems(const QVariantList &vitems, bool *ok = 0, QString *errorMessage = 0) { QList out; @@ -1256,9 +1262,7 @@ class HandlerEngine::Private : public QObject Connection connectionsRefreshedConnection; Connection unsubscribedConnection; Connection reportedConnection; - Connection sendConnection; - Connection expConnection; - Connection errorConnection; + map wsSessionConnectionMap; Connection pullConnection; Connection controlValveConnection; Connection inSubValveConnection; @@ -1695,6 +1699,7 @@ class HandlerEngine::Private : public QObject log_debug("removed ws session: %s", qPrintable(s->cid)); cs.wsSessions.remove(s->cid); + wsSessionConnectionMap.erase(s); delete s; } @@ -2603,9 +2608,11 @@ class HandlerEngine::Private : public QObject if(!s) { s = new WsSession(this); - sendConnection = s->send.connect(boost::bind(&Private::wssession_send, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, s)); - expConnection = s->expired.connect(boost::bind(&Private::wssession_expired, this, s)); - errorConnection = s->error.connect(boost::bind(&Private::wssession_error, this, s)); + wsSessionConnectionMap[s] = { + s->send.connect(boost::bind(&Private::wssession_send, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3, s)), + s->expired.connect(boost::bind(&Private::wssession_expired, this, s)), + s->error.connect(boost::bind(&Private::wssession_error, this, s)) + }; s->cid = QString::fromUtf8(item.cid); s->ttl = item.ttl; s->requestData.uri = item.uri; diff --git a/src/cpp/handler/wssession.h b/src/cpp/handler/wssession.h index 8d1c737c..cdf02df0 100644 --- a/src/cpp/handler/wssession.h +++ b/src/cpp/handler/wssession.h @@ -68,9 +68,9 @@ class WsSession : public QObject void sendDelayed(const QByteArray &type, const QByteArray &message, int timeout); void ack(int reqId); - boost::signals2::signal send; - Signal expired; - Signal error; + boost::signals2::signal send; + Signal expired; + Signal error; private: void setupRequestTimer();