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 #47889

Closed
wants to merge 5 commits into from
Closed
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
21 changes: 9 additions & 12 deletions src/cpp/handler/handlerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,9 @@ class HandlerEngine::Private : public QObject
Connection connectionsRefreshedConnection;
Connection unsubscribedConnection;
Connection reportedConnection;
Connection sendConnection;
Connection expConnection;
Connection errorConnection;
Connection pullConnection;
Connection controlValveConnection;
Connection inSubValveConnection;
Expand Down Expand Up @@ -2600,9 +2603,9 @@ 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);
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;
Expand Down Expand Up @@ -3132,10 +3135,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 +3148,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