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;