From 9930310d955bd1a0030a18e6fba2fad262fb2ed9 Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Thu, 25 Jan 2024 21:04:08 -0800 Subject: [PATCH 1/5] boostificaiton fixes --- src/cpp/handler/handlerengine.cpp | 4 ++-- src/cpp/processquit.cpp | 7 +++---- src/cpp/proxy/sockjsmanager.cpp | 32 ++++++++++++----------------- src/cpp/proxy/sockjssession.cpp | 16 +++++++-------- src/cpp/proxy/websocketoverhttp.cpp | 2 +- src/cpp/qzmq/src/qzmqsocket.cpp | 4 ++-- src/cpp/zrpcmanager.cpp | 2 +- src/cpp/zrpcrequest.cpp | 6 +++--- 8 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/cpp/handler/handlerengine.cpp b/src/cpp/handler/handlerengine.cpp index 148346a3..d4c6af17 100644 --- a/src/cpp/handler/handlerengine.cpp +++ b/src/cpp/handler/handlerengine.cpp @@ -1052,7 +1052,7 @@ class AcceptWorker : public Deferred rp.route = route.toUtf8(); rp.retrySeq = stats->lastRetrySeq(); - emit retryPacketReady(rp); + retryPacketReady(rp); setFinished(true); return; @@ -1117,7 +1117,7 @@ class AcceptWorker : public Deferred // engine should directly connect to this and register the holds // immediately, to avoid a race with the lastId check - emit sessionsReady(); + sessionsReady(); setFinished(true); } diff --git a/src/cpp/processquit.cpp b/src/cpp/processquit.cpp index 79a52265..e1dd0c0b 100644 --- a/src/cpp/processquit.cpp +++ b/src/cpp/processquit.cpp @@ -60,7 +60,7 @@ class SafeSocketNotifier : public QObject QObject(parent) { sn = new QSocketNotifier(socket, type, this); - connect(sn, SIGNAL(activated(int)), SLOT(doActivated())); + connect(sn, &QSocketNotifier::activated, this, &SafeSocketNotifier::doActivated); } ~SafeSocketNotifier() @@ -82,10 +82,9 @@ public slots: private: QSocketNotifier *sn; -private slots: - void doActivated() + void doActivated(int sock) { - activated(sn->socket()); + activated(sock); } }; diff --git a/src/cpp/proxy/sockjsmanager.cpp b/src/cpp/proxy/sockjsmanager.cpp index 76692424..9879a547 100644 --- a/src/cpp/proxy/sockjsmanager.cpp +++ b/src/cpp/proxy/sockjsmanager.cpp @@ -241,9 +241,9 @@ class SockJsManager::Private : public QObject s->route = route; - readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this)); - bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1)); - errorConnection = req->error.connect(boost::bind(&Private::req_error, this)); + readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)); + bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); + errorConnection = req->error.connect(boost::bind(&Private::req_error, this, req)); sessions += s; sessionsByRequest.insert(s->req, s); @@ -364,9 +364,9 @@ class SockJsManager::Private : public QObject { discardedRequests += req; - readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this)); - bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1)); - errorConnection = req->error.connect(boost::bind(&Private::req_error, this)); + readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)); + bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); + errorConnection = req->error.connect(boost::bind(&Private::req_error, this, req)); } HttpHeaders headers; @@ -484,7 +484,7 @@ class SockJsManager::Private : public QObject sessionsById.insert(s->sid, s); s->pending = true; pendingSessions += s; - emit q->sessionReady(); + q->sessionReady(); return; } } @@ -499,7 +499,7 @@ class SockJsManager::Private : public QObject { s->pending = true; pendingSessions += s; - emit q->sessionReady(); + q->sessionReady(); return; } else @@ -514,7 +514,7 @@ class SockJsManager::Private : public QObject s->lastPart = lastPart; s->pending = true; pendingSessions += s; - emit q->sessionReady(); + q->sessionReady(); return; } @@ -575,11 +575,8 @@ class SockJsManager::Private : public QObject return s->ext; } -private slots: - void req_readyRead() + void req_readyRead(ZhttpRequest *req) { - ZhttpRequest *req = (ZhttpRequest *)sender(); - // for a request to have been discardable, we must have read the // entire input already and handed to the session assert(!discardedRequests.contains(req)); @@ -590,12 +587,10 @@ private slots: processRequestInput(s); } - void req_bytesWritten(int count) + void req_bytesWritten(int count, ZhttpRequest *req) { Q_UNUSED(count); - ZhttpRequest *req = (ZhttpRequest *)sender(); - if(discardedRequests.contains(req)) { if(req->isFinished()) @@ -617,10 +612,8 @@ private slots: } } - void req_error() + void req_error(ZhttpRequest *req) { - ZhttpRequest *req = (ZhttpRequest *)sender(); - if(discardedRequests.contains(req)) { discardedRequests.remove(req); @@ -637,6 +630,7 @@ private slots: removeSession(s); } +private slots: void sock_closed() { ZWebSocket *sock = (ZWebSocket *)sender(); diff --git a/src/cpp/proxy/sockjssession.cpp b/src/cpp/proxy/sockjssession.cpp index 099fe52f..e3df9adb 100644 --- a/src/cpp/proxy/sockjssession.cpp +++ b/src/cpp/proxy/sockjssession.cpp @@ -256,8 +256,8 @@ class SockJsSession::Private : public QObject requests.insert(req, new RequestItem(req, jsonpCallback, RequestItem::Connect)); - bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1)); - errorConnection = req->error.connect(boost::bind(&Private::req_error, this)); + bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); + errorConnection = req->error.connect(boost::bind(&Private::req_error, this, req)); } else { @@ -297,8 +297,8 @@ class SockJsSession::Private : public QObject void handleRequest(ZhttpRequest *_req, const QByteArray &jsonpCallback, const QByteArray &lastPart, const QByteArray &body) { - bytesWrittenConnection = _req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1)); - errorConnection = _req->error.connect(boost::bind(&Private::req_error, this)); + bytesWrittenConnection = _req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); + errorConnection = _req->error.connect(boost::bind(&Private::req_error, this, req)); if(lastPart == "xhr" || lastPart == "jsonp") { @@ -871,12 +871,10 @@ class SockJsSession::Private : public QObject return closeValue; } -private slots: - void req_bytesWritten(int count) + void req_bytesWritten(int count, ZhttpRequest *_req) { Q_UNUSED(count); - ZhttpRequest *_req = (ZhttpRequest *)sender(); RequestItem *ri = requests.value(_req); assert(ri); @@ -929,9 +927,8 @@ private slots: } } - void req_error() + void req_error(ZhttpRequest *_req) { - ZhttpRequest *_req = (ZhttpRequest *)sender(); RequestItem *ri = requests.value(_req); assert(ri); @@ -972,6 +969,7 @@ private slots: } } +private slots: void sock_readyRead() { if(mode == WebSocketFramed) diff --git a/src/cpp/proxy/websocketoverhttp.cpp b/src/cpp/proxy/websocketoverhttp.cpp index 640661cc..4d10f39d 100644 --- a/src/cpp/proxy/websocketoverhttp.cpp +++ b/src/cpp/proxy/websocketoverhttp.cpp @@ -641,7 +641,6 @@ class WebSocketOverHttp::Private : public QObject req->endBody(); } -private slots: void req_readyRead() { if(inBuf.size() + req->bytesAvailable() > RESPONSE_BODY_MAX) @@ -981,6 +980,7 @@ private slots: emit q->error(); } +private slots: void keepAliveTimer_timeout() { update(); diff --git a/src/cpp/qzmq/src/qzmqsocket.cpp b/src/cpp/qzmq/src/qzmqsocket.cpp index edd38b88..d17c9b67 100644 --- a/src/cpp/qzmq/src/qzmqsocket.cpp +++ b/src/cpp/qzmq/src/qzmqsocket.cpp @@ -407,7 +407,7 @@ class Socket::Private : public QObject assert(sock != NULL); sn_read = new QSocketNotifier(get_fd(sock), QSocketNotifier::Read, this); - connect(sn_read, SIGNAL(activated(int)), SLOT(sn_read_activated())); + connect(sn_read, &QSocketNotifier::activated, this, &Private::sn_read_activated); sn_read->setEnabled(true); updateTimer = new QTimer(this); @@ -601,7 +601,6 @@ class Socket::Private : public QObject } } -public slots: void sn_read_activated() { if(!processEvents()) @@ -616,6 +615,7 @@ public slots: doUpdate(); } +public slots: void update_timeout() { pendingUpdate = false; diff --git a/src/cpp/zrpcmanager.cpp b/src/cpp/zrpcmanager.cpp index 41447401..bb43e419 100644 --- a/src/cpp/zrpcmanager.cpp +++ b/src/cpp/zrpcmanager.cpp @@ -244,7 +244,7 @@ class ZrpcManager::Private : public QObject if(pending.count() >= PENDING_MAX) serverValve->close(); - emit q->requestReady(); + q->requestReady(); } }; diff --git a/src/cpp/zrpcrequest.cpp b/src/cpp/zrpcrequest.cpp index 5ab87dcb..05c24228 100644 --- a/src/cpp/zrpcrequest.cpp +++ b/src/cpp/zrpcrequest.cpp @@ -129,7 +129,7 @@ class ZrpcRequest::Private : public QObject q->onError(); } - emit q->finished(); + q->finished(); } private slots: @@ -141,7 +141,7 @@ private slots: condition = ErrorUnavailable; conditionString = "service-unavailable"; cleanup(); - emit q->finished(); + q->finished(); return; } @@ -167,7 +167,7 @@ private slots: condition = ErrorTimeout; conditionString = "timeout"; cleanup(); - emit q->finished(); + q->finished(); } }; From 9395792819df4461414692d5d431be2e58a29e36 Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Fri, 26 Jan 2024 06:44:19 -0800 Subject: [PATCH 2/5] comments addressed --- src/cpp/proxy/sockjsmanager.cpp | 28 +++++++++++++++++++--------- src/cpp/proxy/sockjsmanager.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/cpp/proxy/sockjsmanager.cpp b/src/cpp/proxy/sockjsmanager.cpp index 9879a547..90248236 100644 --- a/src/cpp/proxy/sockjsmanager.cpp +++ b/src/cpp/proxy/sockjsmanager.cpp @@ -68,6 +68,12 @@ static QByteArray serializeJsonString(const QString &s) return tmp.mid(1, tmp.length() - 2); } +struct ZhttpReqConnections{ + Connection readyReadConnection; + Connection bytesWrittenConnection; + Connection errorConnection; +}; + class SockJsManager::Private : public QObject { Q_OBJECT @@ -133,9 +139,7 @@ class SockJsManager::Private : public QObject QByteArray iframeHtml; QByteArray iframeHtmlEtag; QSet discardedRequests; - Connection readyReadConnection; - Connection bytesWrittenConnection; - Connection errorConnection; + map reqConnectionMap; Private(SockJsManager *_q, const QString &sockJsUrl) : QObject(_q), @@ -241,9 +245,11 @@ class SockJsManager::Private : public QObject s->route = route; - readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)); - bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); - errorConnection = req->error.connect(boost::bind(&Private::req_error, this, req)); + reqConnectionMap[req] = { + req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)), + req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)), + req->error.connect(boost::bind(&Private::req_error, this, req)) + }; sessions += s; sessionsByRequest.insert(s->req, s); @@ -364,9 +370,11 @@ class SockJsManager::Private : public QObject { discardedRequests += req; - readyReadConnection = req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)); - bytesWrittenConnection = req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)); - errorConnection = req->error.connect(boost::bind(&Private::req_error, this, req)); + reqConnectionMap[req] = { + req->readyRead.connect(boost::bind(&Private::req_readyRead, this, req)), + req->bytesWritten.connect(boost::bind(&Private::req_bytesWritten, this, boost::placeholders::_1, req)), + req->error.connect(boost::bind(&Private::req_error, this, req)) + }; } HttpHeaders headers; @@ -596,6 +604,7 @@ class SockJsManager::Private : public QObject if(req->isFinished()) { discardedRequests.remove(req); + reqConnectionMap.erase(req); delete req; } @@ -614,6 +623,7 @@ class SockJsManager::Private : public QObject void req_error(ZhttpRequest *req) { + reqConnectionMap.erase(req); if(discardedRequests.contains(req)) { discardedRequests.remove(req); diff --git a/src/cpp/proxy/sockjsmanager.h b/src/cpp/proxy/sockjsmanager.h index 676a645f..20759088 100644 --- a/src/cpp/proxy/sockjsmanager.h +++ b/src/cpp/proxy/sockjsmanager.h @@ -28,6 +28,7 @@ #include #include +using std::map; using Signal = boost::signals2::signal; using Connection = boost::signals2::scoped_connection; From 210e8a57d01da584c42d3f5170c4683f5cfed2aa Mon Sep 17 00:00:00 2001 From: sima-fastly Date: Fri, 26 Jan 2024 11:43:22 -0800 Subject: [PATCH 3/5] comments addressed --- src/cpp/proxy/sockjsmanager.cpp | 9 +++++++-- src/cpp/proxy/sockjsmanager.h | 1 - src/cpp/qzmq/src/qzmqsocket.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cpp/proxy/sockjsmanager.cpp b/src/cpp/proxy/sockjsmanager.cpp index 90248236..4a478a8f 100644 --- a/src/cpp/proxy/sockjsmanager.cpp +++ b/src/cpp/proxy/sockjsmanager.cpp @@ -37,6 +37,8 @@ #include "zwebsocket.h" #include "sockjssession.h" +using std::map; + #define MAX_REQUEST_BODY 100000 const char *iframeHtmlTemplate = @@ -116,7 +118,10 @@ class SockJsManager::Private : public QObject ~Session() { - delete req; + if req{ + owner->discardedRequests.remove(req); + delete req; + } delete sock; if(timer) @@ -623,10 +628,10 @@ class SockJsManager::Private : public QObject void req_error(ZhttpRequest *req) { - reqConnectionMap.erase(req); if(discardedRequests.contains(req)) { discardedRequests.remove(req); + reqConnectionMap.erase(req); delete req; return; } diff --git a/src/cpp/proxy/sockjsmanager.h b/src/cpp/proxy/sockjsmanager.h index 20759088..676a645f 100644 --- a/src/cpp/proxy/sockjsmanager.h +++ b/src/cpp/proxy/sockjsmanager.h @@ -28,7 +28,6 @@ #include #include -using std::map; using Signal = boost::signals2::signal; using Connection = boost::signals2::scoped_connection; diff --git a/src/cpp/qzmq/src/qzmqsocket.cpp b/src/cpp/qzmq/src/qzmqsocket.cpp index d17c9b67..e23c3df2 100644 --- a/src/cpp/qzmq/src/qzmqsocket.cpp +++ b/src/cpp/qzmq/src/qzmqsocket.cpp @@ -601,6 +601,7 @@ class Socket::Private : public QObject } } +public slots: void sn_read_activated() { if(!processEvents()) @@ -615,7 +616,6 @@ class Socket::Private : public QObject doUpdate(); } -public slots: void update_timeout() { pendingUpdate = false; From 76fb7a2ce23b415c8160943c0640dc6b1fdea549 Mon Sep 17 00:00:00 2001 From: Sima <64804941+sima-fastly@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:51:45 -0800 Subject: [PATCH 4/5] Update sockjsmanager.cpp --- src/cpp/proxy/sockjsmanager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cpp/proxy/sockjsmanager.cpp b/src/cpp/proxy/sockjsmanager.cpp index 4a478a8f..ee971e01 100644 --- a/src/cpp/proxy/sockjsmanager.cpp +++ b/src/cpp/proxy/sockjsmanager.cpp @@ -118,9 +118,10 @@ class SockJsManager::Private : public QObject ~Session() { - if req{ - owner->discardedRequests.remove(req); - delete req; + if(req) + { + owner->reqConnectionMap.erase(req); + delete req; } delete sock; From 2f958faeb82bbf5290ddf6cf42fcf97d2394cf99 Mon Sep 17 00:00:00 2001 From: Sima <64804941+sima-fastly@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:52:07 -0800 Subject: [PATCH 5/5] Update sockjsmanager.cpp --- src/cpp/proxy/sockjsmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/proxy/sockjsmanager.cpp b/src/cpp/proxy/sockjsmanager.cpp index ee971e01..b26ca31a 100644 --- a/src/cpp/proxy/sockjsmanager.cpp +++ b/src/cpp/proxy/sockjsmanager.cpp @@ -120,8 +120,8 @@ class SockJsManager::Private : public QObject { if(req) { - owner->reqConnectionMap.erase(req); - delete req; + owner->reqConnectionMap.erase(req); + delete req; } delete sock;