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 wscontrol session #47890

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/cpp/proxy/wscontrolsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class WsControlSession::Private : public QObject
else
pendingSendEventWrites += QByteArray(); // placeholder

emit q->sendEventReceived(type, item.message, item.queue);
q->sendEventReceived(type, item.message, item.queue);
}
else if(item.type == WsControlPacket::Item::KeepAliveSetup)
{
Expand All @@ -212,22 +212,22 @@ class WsControlSession::Private : public QObject
mode = WsControl::Interval;
else // idle
mode = WsControl::Idle;
emit q->keepAliveSetupEventReceived(mode, item.timeout);
q->keepAliveSetupEventReceived(mode, item.timeout);
}
else
emit q->keepAliveSetupEventReceived(WsControl::NoKeepAlive);
q->keepAliveSetupEventReceived(WsControl::NoKeepAlive, -1);
}
else if(item.type == WsControlPacket::Item::Close)
{
emit q->closeEventReceived(item.code, item.reason);
q->closeEventReceived(item.code, item.reason);
}
else if(item.type == WsControlPacket::Item::Detach)
{
emit q->detachEventReceived();
q->detachEventReceived();
}
else if(item.type == WsControlPacket::Item::Cancel)
{
emit q->cancelEventReceived();
q->cancelEventReceived();
}
else if(item.type == WsControlPacket::Item::Ack)
{
Expand Down Expand Up @@ -261,7 +261,7 @@ private slots:
pendingRequests.clear();
setupRequestTimer();

emit q->error();
q->error();
}
};

Expand Down
16 changes: 9 additions & 7 deletions src/cpp/proxy/wscontrolsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "websocket.h"
#include "wscontrol.h"
#include "packet/wscontrolpacket.h"
#include <boost/signals2.hpp>

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

class WsControlManager;

Expand All @@ -48,13 +51,12 @@ class WsControlSession : public QObject
// tell session that a received sendEvent has been written
void sendEventWritten();

signals:
void sendEventReceived(WebSocket::Frame::Type type, const QByteArray &message, bool queue);
void keepAliveSetupEventReceived(WsControl::KeepAliveMode mode, int timeout = -1);
void closeEventReceived(int code, const QByteArray &reason); // -1 for no code
void detachEventReceived();
void cancelEventReceived();
void error();
boost::signals2::signal<void(WebSocket::Frame::Type, const QByteArray&, bool)> sendEventReceived;
boost::signals2::signal<void(WsControl::KeepAliveMode, int)> keepAliveSetupEventReceived;
boost::signals2::signal<void(int, const QByteArray&)> closeEventReceived; // Use -1 for no code
Signal detachEventReceived;
Signal cancelEventReceived;
Signal error;

private:
class Private;
Expand Down
18 changes: 11 additions & 7 deletions src/cpp/proxy/wsproxysession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class WsProxySession::Private : public QObject
Callback<std::tuple<WsProxySession *>> finishedByPassthroughCallback;
Connection keepAliveConneciton;
Connection aboutToSendRequestConnection;
map<WsControlSession*, WSProxyConnections> wsProxyConnectionMap;

Private(WsProxySession *_q, ZRoutes *_zroutes, ConnectionManager *_connectionManager, const LogUtil::Config &_logConfig, StatsManager *_statsManager, WsControlManager *_wsControlManager) :
QObject(_q),
Expand Down Expand Up @@ -325,6 +326,7 @@ class WsProxySession::Private : public QObject
delete outSock;
outSock = 0;

wsProxyConnectionMap.erase(wsControl);
delete wsControl;
wsControl = 0;

Expand Down Expand Up @@ -900,12 +902,14 @@ private slots:
if(wsControlManager)
{
wsControl = wsControlManager->createSession(publicCid);
connect(wsControl, &WsControlSession::sendEventReceived, this, &Private::wsControl_sendEventReceived);
connect(wsControl, &WsControlSession::keepAliveSetupEventReceived, this, &Private::wsControl_keepAliveSetupEventReceived);
connect(wsControl, &WsControlSession::closeEventReceived, this, &Private::wsControl_closeEventReceived);
connect(wsControl, &WsControlSession::detachEventReceived, this, &Private::wsControl_detachEventReceived);
connect(wsControl, &WsControlSession::cancelEventReceived, this, &Private::wsControl_cancelEventReceived);
connect(wsControl, &WsControlSession::error, this, &Private::wsControl_error);
wsProxyConnectionMap[wsControl] = {
wsControl->sendEventReceived.connect(boost::bind(&Private::wsControl_sendEventReceived, this, boost::placeholders::_1, boost::placeholders::_2, boost::placeholders::_3)),
wsControl->keepAliveSetupEventReceived.connect(boost::bind(&Private::wsControl_keepAliveSetupEventReceived, this, boost::placeholders::_1, boost::placeholders::_2)),
wsControl->closeEventReceived.connect(boost::bind(&Private::wsControl_closeEventReceived, this, boost::placeholders::_1, boost::placeholders::_2)),
wsControl->detachEventReceived.connect(boost::bind(&Private::wsControl_detachEventReceived, this)),
wsControl->cancelEventReceived.connect(boost::bind(&Private::wsControl_cancelEventReceived, this)),
wsControl->error.connect(boost::bind(&Private::wsControl_error, this))
};
wsControl->start(route.id, route.separateStats, channelPrefix, inSock->requestUri());

foreach(const QString &subChannel, target.subscriptions)
Expand Down Expand Up @@ -1014,6 +1018,7 @@ private slots:
woh->setHeaders(requestData.headers);
}

private:
void wsControl_sendEventReceived(WebSocket::Frame::Type type, const QByteArray &message, bool queue)
{
// this method accepts a full message, which must be typed
Expand Down Expand Up @@ -1114,7 +1119,6 @@ private slots:
wsControl_cancelEventReceived();
}

private:
void keepAliveTimer_timeout()
{
wsControl->sendNeedKeepAlive();
Expand Down
11 changes: 10 additions & 1 deletion src/cpp/proxy/wsproxysession.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include "callback.h"
#include "logutil.h"
#include "domainmap.h"

#include <boost/signals2.hpp>

using std::map;
using Connection = boost::signals2::scoped_connection;

namespace Jwt {
Expand Down Expand Up @@ -81,4 +81,13 @@ class WsProxySession : public QObject
Private *d;
};

struct WSProxyConnections {
Connection sendEventReceivedConnection;
Connection keepAliveSetupEventReceivedConnection;
Connection closeEventReceivedConnection;
Connection detachEventReceivedConnection;
Connection cancelEventReceivedConnection;
Connection errorConnection;
};

#endif
Loading