Skip to content

Commit

Permalink
more req session boostification
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-fastly committed Jan 29, 2024
1 parent b898764 commit 30cf283
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
23 changes: 10 additions & 13 deletions src/cpp/proxy/proxysession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ using std::map;
#define MAX_STREAM_BUFFER 100000

struct RequestSessionConnections {
Connection bytesWrittenConnection;
Connection errorRespondingConnection;
Connection pausedConnection;
Connection headerBytesSentConnection;
Connection bodyBytesSentConnection;
};

class ProxySession::Private : public QObject
Expand Down Expand Up @@ -246,14 +249,14 @@ class ProxySession::Private : public QObject

sessionItems += si;
sessionItemsBySession.insert(rs, si);
connect(rs, &RequestSession::bytesWritten, this, &Private::rs_bytesWritten);
connect(rs, &RequestSession::finished, this, &Private::rs_finished);
reqSessionConnectionMap[rs] = {
rs->bytesWritten.connect(boost::bind(&Private::rs_bytesWritten, this, boost::placeholders::_1, rs)),
rs->errorResponding.connect(boost::bind(&Private::rs_errorResponding, this, rs)),
rs->paused.connect(boost::bind(&Private::rs_paused, this, rs))
rs->paused.connect(boost::bind(&Private::rs_paused, this, rs)),
rs->headerBytesSent.connect(boost::bind(&Private::rs_headerBytesSent, this, boost::placeholders::_1, rs)),
rs->bodyBytesSent.connect(boost::bind(&Private::rs_bodyBytesSent, this, boost::placeholders::_1, rs))
};
connect(rs, &RequestSession::headerBytesSent, this, &Private::rs_headerBytesSent);
connect(rs, &RequestSession::bodyBytesSent, this, &Private::rs_bodyBytesSent);

HttpRequestData rsRequestData = rs->requestData();

Expand Down Expand Up @@ -1178,10 +1181,8 @@ class ProxySession::Private : public QObject
}

public slots:
void rs_bytesWritten(int count)
void rs_bytesWritten(int count, RequestSession *rs)
{
RequestSession *rs = (RequestSession *)sender();

log_debug("proxysession: %p response bytes written id=%s: %d", q, rs->rid().second.data(), count);

SessionItem *si = sessionItemsBySession.value(rs);
Expand Down Expand Up @@ -1357,21 +1358,17 @@ public slots:
// don't destroy the RequestSession here. a finished signal will arrive next.
}

void rs_headerBytesSent(int count)
void rs_headerBytesSent(int count, RequestSession *rs)
{
RequestSession *rs = (RequestSession *)sender();

SessionItem *si = sessionItemsBySession.value(rs);
assert(si);

if(si->countClientSentBytes)
incCounter(Stats::ClientHeaderBytesSent, count);
}

void rs_bodyBytesSent(int count)
void rs_bodyBytesSent(int count, RequestSession *rs)
{
RequestSession *rs = (RequestSession *)sender();

SessionItem *si = sessionItemsBySession.value(rs);
assert(si);

Expand Down
4 changes: 2 additions & 2 deletions src/cpp/proxy/requestsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ void RequestSession::startResponse(int code, const QByteArray &reason, const Htt
{
assert(d->state == Private::ReceivingForAccept || d->state == Private::WaitingForResponse);

emit headerBytesSent(ZhttpManager::estimateResponseHeaderBytes(code, reason, headers));
headerBytesSent(ZhttpManager::estimateResponseHeaderBytes(code, reason, headers));

d->state = Private::RespondingStart;
d->responseData.code = code;
Expand All @@ -1372,7 +1372,7 @@ void RequestSession::writeResponseBody(const QByteArray &body)
assert(d->state == Private::RespondingStart || d->state == Private::Responding);
assert(!d->responseBodyFinished);

emit bodyBytesSent(body.size());
bodyBytesSent(body.size());

d->out += body;
d->responseUpdate();
Expand Down
13 changes: 7 additions & 6 deletions src/cpp/proxy/requestsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <boost/signals2.hpp>

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

class QHostAddress;
Expand Down Expand Up @@ -102,10 +103,13 @@ class RequestSession : public QObject

int unregisterConnection(); // return unreported time

boost::signals2::signal<void(const InspectData&)> inspected;
Signal inspectError;
Signal paused;
Signal finishedByAccept;
boost::signals2::signal<void(const InspectData&)> inspected;
Signal finishedByAccept;
SignalInt bytesWritten;
Signal paused;
SignalInt headerBytesSent;
SignalInt bodyBytesSent;
// this signal means some error was encountered while responding and
// that you should not attempt to call further response-related
// methods. the object remains in an active state though, and so you
Expand All @@ -114,9 +118,6 @@ class RequestSession : public QObject

signals:
void finished();
void bytesWritten(int count);
void headerBytesSent(int count);
void bodyBytesSent(int count);

private:
class Private;
Expand Down

0 comments on commit 30cf283

Please sign in to comment.