diff --git a/src/cpp/httprequest.h b/src/cpp/httprequest.h index 1901f889..99c54368 100644 --- a/src/cpp/httprequest.h +++ b/src/cpp/httprequest.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2012-2016 Fanout, Inc. - * Copyright (C) 2023 Fastly, Inc. + * Copyright (C) 2023-2024 Fastly, Inc. * * This file is part of Pushpin. * @@ -24,19 +24,17 @@ #ifndef HTTPREQUEST_H #define HTTPREQUEST_H -#include #include #include #include "httpheaders.h" #include +#include using Signal = boost::signals2::signal; using SignalInt = boost::signals2::signal; -class HttpRequest : public QObject +class HttpRequest { - Q_OBJECT - public: enum ErrorCondition { @@ -52,7 +50,7 @@ class HttpRequest : public QObject ErrorRequestTooLarge }; - HttpRequest(QObject *parent = 0) : QObject(parent) {} + HttpRequest() {} virtual QHostAddress peerAddress() const = 0; diff --git a/src/cpp/proxy/testhttprequest.cpp b/src/cpp/proxy/testhttprequest.cpp index dfe36308..672d8caa 100644 --- a/src/cpp/proxy/testhttprequest.cpp +++ b/src/cpp/proxy/testhttprequest.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Fanout, Inc. + * Copyright (C) 2024 Fastly, Inc. * * This file is part of Pushpin. * @@ -32,10 +33,8 @@ #define MAX_REQUEST_SIZE 100000 -class TestHttpRequest::Private : public QObject -{ - Q_OBJECT - +class TestHttpRequest::Private +{ public: enum State { @@ -55,7 +54,6 @@ class TestHttpRequest::Private : public QObject ErrorCondition errorCondition; Private(TestHttpRequest *_q) : - QObject(_q), q(_q), state(Idle), requestBodyFinished(false), @@ -139,10 +137,10 @@ public slots: } }; -TestHttpRequest::TestHttpRequest(QObject *parent) : - HttpRequest(parent) +TestHttpRequest::TestHttpRequest() : + HttpRequest() { - d = new Private(this); + d = std::make_unique(this); } TestHttpRequest::~TestHttpRequest() diff --git a/src/cpp/proxy/testhttprequest.h b/src/cpp/proxy/testhttprequest.h index a9873d8e..3369564c 100644 --- a/src/cpp/proxy/testhttprequest.h +++ b/src/cpp/proxy/testhttprequest.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Fanout, Inc. + * Copyright (C) 2024 Fastly, Inc. * * This file is part of Pushpin. * @@ -24,16 +25,15 @@ #define TESTHTTPREQUEST_H #include "httprequest.h" +#include class TestHttpRequest : public HttpRequest { - Q_OBJECT - public: // pair of sender + request id typedef QPair Rid; - TestHttpRequest(QObject *parent = 0); + TestHttpRequest(); ~TestHttpRequest(); // reimplemented @@ -74,7 +74,7 @@ class TestHttpRequest : public HttpRequest private: class Private; friend class Private; - Private *d; + std::unique_ptr d; }; #endif diff --git a/src/cpp/rtimer.cpp b/src/cpp/rtimer.cpp index ef2cb471..1e605bad 100644 --- a/src/cpp/rtimer.cpp +++ b/src/cpp/rtimer.cpp @@ -26,6 +26,7 @@ #include #include #include "timerwheel.h" +#include #define TICK_DURATION_MS 10 #define UPDATE_TICKS_MAX 1000 @@ -46,37 +47,33 @@ static qint64 ticksToDuration(qint64 ticks) return ticks * TICK_DURATION_MS; } -class TimerManager : public QObject +class TimerManager { - Q_OBJECT - public: - TimerManager(int capacity, QObject *parent = 0); + TimerManager(int capacity); int add(int msec, RTimer *r); void remove(int key); -private slots: +private: void t_timeout(); -private: TimerWheel wheel_; qint64 startTime_; quint64 currentTicks_; - QTimer *t_; + std::unique_ptr t_; void updateTimeout(qint64 currentTime); }; -TimerManager::TimerManager(int capacity, QObject *parent) : - QObject(parent), +TimerManager::TimerManager(int capacity) : wheel_(TimerWheel(capacity)) { startTime_ = QDateTime::currentMSecsSinceEpoch(); currentTicks_ = 0; - t_ = new QTimer(this); - connect(t_, &QTimer::timeout, this, &TimerManager::t_timeout); + t_ = std::make_unique(this); + QObject::connect(t_.get(), &QTimer::timeout, this, &TimerManager::t_timeout); t_->setSingleShot(true); } @@ -170,10 +167,9 @@ void TimerManager::updateTimeout(qint64 currentTime) } } -static TimerManager *g_manager = 0; +static std::unique_ptr g_manager = nullptr; -RTimer::RTimer(QObject *parent) : - QObject(parent), +RTimer::RTimer() : singleShot_(false), interval_(0), timerId_(-1) @@ -243,7 +239,7 @@ void RTimer::init(int capacity) { assert(!g_manager); - g_manager = new TimerManager(capacity); + g_manager = std::make_unique(capacity); } void RTimer::deinit() @@ -251,5 +247,3 @@ void RTimer::deinit() delete g_manager; g_manager = 0; } - -#include "rtimer.moc" diff --git a/src/cpp/rtimer.h b/src/cpp/rtimer.h index ffacf13c..dd56d18a 100644 --- a/src/cpp/rtimer.h +++ b/src/cpp/rtimer.h @@ -30,12 +30,10 @@ using Signal = boost::signals2::signal; class TimerManager; -class RTimer : public QObject +class RTimer { - Q_OBJECT - public: - RTimer(QObject *parent = 0); + RTimer(); ~RTimer(); bool isActive() const; diff --git a/src/cpp/zhttpmanager.cpp b/src/cpp/zhttpmanager.cpp index 96f3b49e..92aec530 100644 --- a/src/cpp/zhttpmanager.cpp +++ b/src/cpp/zhttpmanager.cpp @@ -35,6 +35,7 @@ #include "log.h" #include "zutil.h" #include "logutil.h" +#include #define OUT_HWM 100 #define IN_HWM 100 @@ -54,10 +55,8 @@ // needs to match the peer #define ZHTTP_IDS_MAX 128 -class ZhttpManager::Private : public QObject +class ZhttpManager::Private { - Q_OBJECT - public: enum SessionType { @@ -82,25 +81,25 @@ class ZhttpManager::Private : public QObject QStringList server_in_specs; QStringList server_in_stream_specs; QStringList server_out_specs; - QZmq::Socket *client_out_sock; - QZmq::Socket *client_out_stream_sock; - QZmq::Socket *client_in_sock; - QZmq::Socket *client_req_sock; - QZmq::Socket *server_in_sock; - QZmq::Socket *server_in_stream_sock; - QZmq::Socket *server_out_sock; - QZmq::Valve *client_in_valve; - QZmq::Valve *server_in_valve; - QZmq::Valve *server_in_stream_valve; + std::unique_ptr client_out_sock; + std::unique_ptr client_out_stream_sock; + std::unique_ptr client_in_sock; + std::unique_ptr client_req_sock; + std::unique_ptr server_in_sock; + std::unique_ptr server_in_stream_sock; + std::unique_ptr server_out_sock; + std::unique_ptr client_in_valve; + std::unique_ptr server_in_valve; + std::unique_ptr server_in_stream_valve; QByteArray instanceId; int ipcFileMode; bool doBind; - QHash clientReqsByRid; - QHash serverReqsByRid; + QHash> clientReqsByRid; + QHash> serverReqsByRid; QList serverPendingReqs; - QHash clientSocksByRid; - QHash serverSocksByRid; - QList serverPendingSocks; + QHash> clientSocksByRid; + QHash> serverSocksByRid; + QList> serverPendingSocks; QTimer *refreshTimer; QHash keepAliveRegistrations; QSet sessionRefreshBuckets[ZHTTP_REFRESH_BUCKETS]; @@ -114,7 +113,6 @@ class ZhttpManager::Private : public QObject Connection serverStreamConnection; Private(ZhttpManager *_q) : - QObject(_q), q(_q), client_out_sock(0), client_out_stream_sock(0), @@ -507,8 +505,6 @@ class ZhttpManager::Private : public QObject void client_req_readyRead() { - QPointer self = this; - while(client_req_sock->canRead()) { QList msg = client_req_sock->read(); @@ -606,8 +602,6 @@ class ZhttpManager::Private : public QObject return; } - QPointer self = this; - foreach(const ZhttpResponsePacket::Id &id, p.ids) { // is this for a websocket? @@ -774,8 +768,6 @@ class ZhttpManager::Private : public QObject return; } - QPointer self = this; - foreach(const ZhttpRequestPacket::Id &id, p.ids) { // is this for a websocket? @@ -949,10 +941,8 @@ public slots: } }; -ZhttpManager::ZhttpManager(QObject *parent) : - QObject(parent) -{ - d = new Private(this); +ZhttpManager::ZhttpManager() { + d = std::make_unique(this); } ZhttpManager::~ZhttpManager() @@ -1239,5 +1229,3 @@ int ZhttpManager::estimateResponseHeaderBytes(int code, const QByteArray &reason return total; } - -#include "zhttpmanager.moc" diff --git a/src/cpp/zhttpmanager.h b/src/cpp/zhttpmanager.h index 0994170c..197e7cb8 100644 --- a/src/cpp/zhttpmanager.h +++ b/src/cpp/zhttpmanager.h @@ -23,22 +23,20 @@ #ifndef ZHTTPMANAGER_H #define ZHTTPMANAGER_H -#include #include "zhttprequest.h" #include "zwebsocket.h" #include +#include using Signal = boost::signals2::signal; class ZhttpRequestPacket; class ZhttpResponsePacket; -class ZhttpManager : public QObject +class ZhttpManager { - Q_OBJECT - public: - ZhttpManager(QObject *parent = 0); + ZhttpManager(); ~ZhttpManager(); int connectionCount() const; @@ -79,7 +77,7 @@ class ZhttpManager : public QObject private: class Private; friend class Private; - Private *d; + std::unique_ptr d; friend class ZhttpRequest; friend class ZWebSocket; diff --git a/src/cpp/zhttprequest.cpp b/src/cpp/zhttprequest.cpp index 2a0fcb22..c16eba68 100644 --- a/src/cpp/zhttprequest.cpp +++ b/src/cpp/zhttprequest.cpp @@ -32,16 +32,15 @@ #include "rtimer.h" #include "zhttpmanager.h" #include "uuidutil.h" +#include #define IDEAL_CREDITS 200000 #define SESSION_EXPIRE 60000 #define KEEPALIVE_INTERVAL 45000 #define REQ_BUF_MAX 1000000 -class ZhttpRequest::Private : public QObject +class ZhttpRequest::Private { - Q_OBJECT - public: enum State { @@ -99,15 +98,14 @@ class ZhttpRequest::Private : public QObject bool writableChanged; bool errored; ErrorCondition errorCondition; - RTimer *expireTimer; - RTimer *keepAliveTimer; + std::unique_ptr expireTimer; + std::unique_ptr keepAliveTimer; bool multi; bool quiet; Connection expTimerConnection; Connection keepAliveTimerConnection; Private(ZhttpRequest *_q) : - QObject(_q), q(_q), manager(0), server(false), @@ -132,16 +130,14 @@ class ZhttpRequest::Private : public QObject readableChanged(false), writableChanged(false), errored(false), - expireTimer(0), - keepAliveTimer(0), multi(false), quiet(false) { - expireTimer = new RTimer(this); + expireTimer = std::make_unique(this); expTimerConnection = expireTimer->timeout.connect(boost::bind(&Private::expire_timeout, this)); expireTimer->setSingleShot(true); - keepAliveTimer = new RTimer(this); + keepAliveTimer = std::make_unique(this); keepAliveTimerConnection = keepAliveTimer->timeout.connect(boost::bind(&Private::keepAlive_timeout, this)); } @@ -161,7 +157,7 @@ class ZhttpRequest::Private : public QObject if(expireTimer) { - expireTimer->disconnect(this); + expireTimer->unref()->disconnect(this); expireTimer->setParent(0); expireTimer->deleteLater(); expireTimer = 0; @@ -409,8 +405,6 @@ class ZhttpRequest::Private : public QObject void tryWrite() { - QPointer self = this; - if(state == ClientRequesting) { // if all we have to send is EOF, we don't need credits for that @@ -1043,7 +1037,6 @@ public slots: } else if(state == ClientRequesting) { - QPointer self = this; tryWrite(); if(!self) return; @@ -1129,8 +1122,6 @@ public slots: cleanup(); } - QPointer self = this; - if(!packet.body.isEmpty()) q->bytesWritten(packet.body.size()); else if(!packet.more) @@ -1143,7 +1134,6 @@ public slots: } else if(state == ServerResponding) { - QPointer self = this; tryWrite(); if(!self) return; @@ -1183,10 +1173,10 @@ public slots: } }; -ZhttpRequest::ZhttpRequest(QObject *parent) : - HttpRequest(parent) +ZhttpRequest::ZhttpRequest() : + HttpRequest() { - d = new Private(this); + d = std::make_unique(); } ZhttpRequest::~ZhttpRequest() @@ -1455,5 +1445,3 @@ void ZhttpRequest::handle(const QByteArray &id, int seq, const ZhttpResponsePack d->handle(id, seq, packet); } - -#include "zhttprequest.moc" diff --git a/src/cpp/zhttprequest.h b/src/cpp/zhttprequest.h index cefba914..e94de494 100644 --- a/src/cpp/zhttprequest.h +++ b/src/cpp/zhttprequest.h @@ -35,8 +35,6 @@ class ZhttpManager; class ZhttpRequest : public HttpRequest { - Q_OBJECT - public: // pair of sender + request id typedef QPair Rid; @@ -117,7 +115,7 @@ class ZhttpRequest : public HttpRequest private: class Private; friend class Private; - Private *d; + std::unique_ptr d; friend class ZhttpManager; ZhttpRequest(QObject *parent = 0);