Skip to content

Commit

Permalink
comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-fastly committed Jan 26, 2024
1 parent 87c25fa commit 9395792
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/cpp/proxy/sockjsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,9 +139,7 @@ class SockJsManager::Private : public QObject
QByteArray iframeHtml;
QByteArray iframeHtmlEtag;
QSet<ZhttpRequest*> discardedRequests;
Connection readyReadConnection;
Connection bytesWrittenConnection;
Connection errorConnection;
map<ZhttpRequest*, ZhttpReqConnections> reqConnectionMap;

Private(SockJsManager *_q, const QString &sockJsUrl) :
QObject(_q),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -596,6 +604,7 @@ class SockJsManager::Private : public QObject
if(req->isFinished())
{
discardedRequests.remove(req);
reqConnectionMap.erase(req);
delete req;
}

Expand All @@ -614,6 +623,7 @@ class SockJsManager::Private : public QObject

void req_error(ZhttpRequest *req)
{
reqConnectionMap.erase(req);
if(discardedRequests.contains(req))
{
discardedRequests.remove(req);
Expand Down
1 change: 1 addition & 0 deletions src/cpp/proxy/sockjsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <boost/signals2.hpp>
#include <boost/signals2.hpp>

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

Expand Down

0 comments on commit 9395792

Please sign in to comment.