Skip to content

Commit

Permalink
in works
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-fastly committed Feb 8, 2024
1 parent bd004c3 commit 12f16fd
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 101 deletions.
10 changes: 4 additions & 6 deletions src/cpp/httprequest.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -24,19 +24,17 @@
#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H

#include <QObject>
#include <QUrl>
#include <QHostAddress>
#include "httpheaders.h"
#include <boost/signals2.hpp>
#include <memory>

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

class HttpRequest : public QObject
class HttpRequest
{
Q_OBJECT

public:
enum ErrorCondition
{
Expand All @@ -52,7 +50,7 @@ class HttpRequest : public QObject
ErrorRequestTooLarge
};

HttpRequest(QObject *parent = 0) : QObject(parent) {}
HttpRequest() {}

virtual QHostAddress peerAddress() const = 0;

Expand Down
14 changes: 6 additions & 8 deletions src/cpp/proxy/testhttprequest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -32,10 +33,8 @@

#define MAX_REQUEST_SIZE 100000

class TestHttpRequest::Private : public QObject
{
Q_OBJECT

class TestHttpRequest::Private
{
public:
enum State
{
Expand All @@ -55,7 +54,6 @@ class TestHttpRequest::Private : public QObject
ErrorCondition errorCondition;

Private(TestHttpRequest *_q) :
QObject(_q),
q(_q),
state(Idle),
requestBodyFinished(false),
Expand Down Expand Up @@ -139,10 +137,10 @@ public slots:
}
};

TestHttpRequest::TestHttpRequest(QObject *parent) :
HttpRequest(parent)
TestHttpRequest::TestHttpRequest() :
HttpRequest()
{
d = new Private(this);
d = std::make_unique<Private>(this);
}

TestHttpRequest::~TestHttpRequest()
Expand Down
8 changes: 4 additions & 4 deletions src/cpp/proxy/testhttprequest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand All @@ -24,16 +25,15 @@
#define TESTHTTPREQUEST_H

#include "httprequest.h"
#include <memory>

class TestHttpRequest : public HttpRequest
{
Q_OBJECT

public:
// pair of sender + request id
typedef QPair<QByteArray, QByteArray> Rid;

TestHttpRequest(QObject *parent = 0);
TestHttpRequest();
~TestHttpRequest();

// reimplemented
Expand Down Expand Up @@ -74,7 +74,7 @@ class TestHttpRequest : public HttpRequest
private:
class Private;
friend class Private;
Private *d;
std::unique_ptr<Private> d;
};

#endif
28 changes: 11 additions & 17 deletions src/cpp/rtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QDateTime>
#include <QTimer>
#include "timerwheel.h"
#include <memory>

#define TICK_DURATION_MS 10
#define UPDATE_TICKS_MAX 1000
Expand All @@ -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<QTimer> 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<QTimer>(this);
QObject::connect(t_.get(), &QTimer::timeout, this, &TimerManager::t_timeout);
t_->setSingleShot(true);
}

Expand Down Expand Up @@ -170,10 +167,9 @@ void TimerManager::updateTimeout(qint64 currentTime)
}
}

static TimerManager *g_manager = 0;
static std::unique_ptr<TimerManager> g_manager = nullptr;

RTimer::RTimer(QObject *parent) :
QObject(parent),
RTimer::RTimer() :
singleShot_(false),
interval_(0),
timerId_(-1)
Expand Down Expand Up @@ -243,13 +239,11 @@ void RTimer::init(int capacity)
{
assert(!g_manager);

g_manager = new TimerManager(capacity);
g_manager = std::make_unique<TimerManager>(capacity);
}

void RTimer::deinit()
{
delete g_manager;
g_manager = 0;
}

#include "rtimer.moc"
6 changes: 2 additions & 4 deletions src/cpp/rtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ using Signal = boost::signals2::signal<void()>;

class TimerManager;

class RTimer : public QObject
class RTimer
{
Q_OBJECT

public:
RTimer(QObject *parent = 0);
RTimer();
~RTimer();

bool isActive() const;
Expand Down
50 changes: 19 additions & 31 deletions src/cpp/zhttpmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "log.h"
#include "zutil.h"
#include "logutil.h"
#include <memory>

#define OUT_HWM 100
#define IN_HWM 100
Expand All @@ -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
{
Expand All @@ -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<QZmq::Socket> client_out_sock;
std::unique_ptr<QZmq::Socket> client_out_stream_sock;
std::unique_ptr<QZmq::Socket> client_in_sock;
std::unique_ptr<QZmq::Socket> client_req_sock;
std::unique_ptr<QZmq::Socket> server_in_sock;
std::unique_ptr<QZmq::Socket> server_in_stream_sock;
std::unique_ptr<QZmq::Socket> server_out_sock;
std::unique_ptr<QZmq::Valve> client_in_valve;
std::unique_ptr<QZmq::Valve> server_in_valve;
std::unique_ptr<QZmq::Valve> server_in_stream_valve;
QByteArray instanceId;
int ipcFileMode;
bool doBind;
QHash<ZhttpRequest::Rid, ZhttpRequest*> clientReqsByRid;
QHash<ZhttpRequest::Rid, ZhttpRequest*> serverReqsByRid;
QHash<ZhttpRequest::Rid, std::unique_ptr<ZhttpRequest>> clientReqsByRid;
QHash<ZhttpRequest::Rid, std::unique_ptr<ZhttpRequest>> serverReqsByRid;
QList<ZhttpRequest*> serverPendingReqs;
QHash<ZWebSocket::Rid, ZWebSocket*> clientSocksByRid;
QHash<ZWebSocket::Rid, ZWebSocket*> serverSocksByRid;
QList<ZWebSocket*> serverPendingSocks;
QHash<ZWebSocket::Rid, std::unique_ptr<ZWebSocket>> clientSocksByRid;
QHash<ZWebSocket::Rid, std::unique_ptr<ZWebSocket>> serverSocksByRid;
QList<std::unique_ptr<ZWebSocket>> serverPendingSocks;
QTimer *refreshTimer;
QHash<void*, KeepAliveRegistration*> keepAliveRegistrations;
QSet<KeepAliveRegistration*> sessionRefreshBuckets[ZHTTP_REFRESH_BUCKETS];
Expand All @@ -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),
Expand Down Expand Up @@ -507,8 +505,6 @@ class ZhttpManager::Private : public QObject

void client_req_readyRead()
{
QPointer<QObject> self = this;

while(client_req_sock->canRead())
{
QList<QByteArray> msg = client_req_sock->read();
Expand Down Expand Up @@ -606,8 +602,6 @@ class ZhttpManager::Private : public QObject
return;
}

QPointer<QObject> self = this;

foreach(const ZhttpResponsePacket::Id &id, p.ids)
{
// is this for a websocket?
Expand Down Expand Up @@ -774,8 +768,6 @@ class ZhttpManager::Private : public QObject
return;
}

QPointer<QObject> self = this;

foreach(const ZhttpRequestPacket::Id &id, p.ids)
{
// is this for a websocket?
Expand Down Expand Up @@ -949,10 +941,8 @@ public slots:
}
};

ZhttpManager::ZhttpManager(QObject *parent) :
QObject(parent)
{
d = new Private(this);
ZhttpManager::ZhttpManager() {
d = std::make_unique<Private>(this);
}

ZhttpManager::~ZhttpManager()
Expand Down Expand Up @@ -1239,5 +1229,3 @@ int ZhttpManager::estimateResponseHeaderBytes(int code, const QByteArray &reason

return total;
}

#include "zhttpmanager.moc"
10 changes: 4 additions & 6 deletions src/cpp/zhttpmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@
#ifndef ZHTTPMANAGER_H
#define ZHTTPMANAGER_H

#include <QObject>
#include "zhttprequest.h"
#include "zwebsocket.h"
#include <boost/signals2.hpp>
#include <memory>

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

class ZhttpRequestPacket;
class ZhttpResponsePacket;

class ZhttpManager : public QObject
class ZhttpManager
{
Q_OBJECT

public:
ZhttpManager(QObject *parent = 0);
ZhttpManager();
~ZhttpManager();

int connectionCount() const;
Expand Down Expand Up @@ -79,7 +77,7 @@ class ZhttpManager : public QObject
private:
class Private;
friend class Private;
Private *d;
std::unique_ptr<Private> d;

friend class ZhttpRequest;
friend class ZWebSocket;
Expand Down
Loading

0 comments on commit 12f16fd

Please sign in to comment.