Commit 801b7295 authored by Ciarán Ó Rourke's avatar Ciarán Ó Rourke
Browse files

Further additions to get request

parent 52ee3f48
......@@ -106,12 +106,31 @@ void GetRequestHandler::readFile(folly::EventBase* evb)
return;
}
evb->runInEventBaseThread([this, body=buf.move()] () mutable {
ResponseBuilder(downstream_)
evb->runInEventBaseThread([this, body=buf] () mutable {
proxygen::ResponseBuilder(downstream_)
.body(std::move(body))
.send();
});
}
void GetRequestHandler::onEgressPaused() noexcept {
// This will terminate readFile soon
VLOG(4) << "GetRequestHandler pause";
paused_ = true;
}
void GetRequestHandler::onEgressResumed() noexcept {
VLOG(4) << "GetRequestHandler resumed";
pause_ = false;
// If readFileScheduled_, it will reschedule itself
if (!readFileScheduled_ && file_) {
readFileScheduled_ = true;
folly:getCPUExecutor()->add(
std::bind(&GetRequestHandler::readFile, this,
folly::EventBaseManager::get()->getEventBase()));
} else {
VLOG(4) << "Deferred scheduling readFile";
}
}
void GetRequestHandler::onBody(std::unique_ptr<folly::IOBuf> /*body*/) noexcept
......@@ -128,12 +147,25 @@ void GetRequestHandler::onUpgrade(proxygen::UpgradeProtocol /*protocol*/) noexce
void GetRequestHandler::requestComplete() noexcept
{
delete this;
finished_ = true;
paused = true;
checkForCompletion();
}
void GetRequestHandler::onError(proxygen::ProxygenError /*err*/) noexcept
{
delete this;
finished_ = true;
paused = true;
checkForCompletion();
}
bool GetRequestHandler::checkForCompletion() {
if (finished_ && !readFileScheduled_) {
VLOG(4) << "deleting GetRequestHandler";
delete this;
retur true;
}
return false;
}
} // namespace fiphoboserver
......@@ -26,8 +26,6 @@ class GetRequestHandler : public proxygen::RequestHandler {
void onRequest(
std::unique_ptr<proxygen::HTTPMessage> headers) noexcept override;
void readFile(folly::EventBase* evb);
void onBody(std::unique_ptr<folly::IOBuf> body) noexcept override;
void onEOM() noexcept override;
......@@ -38,9 +36,19 @@ class GetRequestHandler : public proxygen::RequestHandler {
void onError(proxygen::ProxygenError err) noexcept override;
void onEgressPaused() noexcept override;
void onEgressResumed() noexcept override;
private:
void readFile(folly::EventBase* evb);
bool checkForCompletion();
S3_header s3_header;
FiPhobo phobos;
bool readFileScheduled_{false};
std::atomic<bool> paused_{false};
bool finished_{false};
};
} // namespace fiphoboserver
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment