Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boostification of wsSession #47891

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/cpp/handler/handlerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@

using namespace VariantUtil;

struct WSSessionConnections {
Connection sendConnection;
Connection expConnection;
Connection errorConnection;
};

static QList<PublishItem> parseItems(const QVariantList &vitems, bool *ok = 0, QString *errorMessage = 0)
{
QList<PublishItem> out;
Expand Down Expand Up @@ -1256,6 +1262,7 @@ class HandlerEngine::Private : public QObject
Connection connectionsRefreshedConnection;
Connection unsubscribedConnection;
Connection reportedConnection;
map<WsSession*, WSSessionConnections> wsSessionConnectionMap;
Connection pullConnection;
Connection controlValveConnection;
Connection inSubValveConnection;
Expand Down Expand Up @@ -1692,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;
}

Expand Down Expand Up @@ -2600,9 +2608,11 @@ class HandlerEngine::Private : public QObject
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);
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;
Expand Down Expand Up @@ -3132,10 +3142,8 @@ private slots:
writeRetryPacket(rp);
}

void wssession_send(int reqId, const QByteArray &type, const QByteArray &message)
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);
Expand All @@ -3147,17 +3155,13 @@ private slots:
writeWsControlItems(QList<WsControlPacket::Item>() << 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;
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/handler/wssession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void WsSession::expireTimer_timeout()
{
log_debug("timing out ws session: %s", qPrintable(cid));

emit expired();
expired();
}

void WsSession::delayedTimer_timeout()
Expand All @@ -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()
Expand All @@ -144,5 +144,5 @@ void WsSession::requestTimer_timeout()
pendingRequests.clear();
setupRequestTimer();

emit error();
error();
}
11 changes: 7 additions & 4 deletions src/cpp/handler/wssession.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <QHash>
#include <QSet>
#include "packet/httprequestdata.h"
#include <boost/signals2.hpp>

using Signal = boost::signals2::signal<void()>;
using Connection = boost::signals2::scoped_connection;

class QTimer;

Expand Down Expand Up @@ -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<void(int, const QByteArray&, const QByteArray&)> send;
Signal expired;
Signal error;

private:
void setupRequestTimer();
Expand Down
Loading