Unverified Commit 56334211 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #118 from dgreatwood/checkBeforeCallOnDone

Check inflightRequests not empty to grab el; and check onDone non-null to call
parents 7ab86e10 f9ee1bcc
......@@ -463,43 +463,55 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) {
parser_.feed(buffer, bytes);
if (parser_.parse() == Private::State::Done) {
auto req = std::move(inflightRequests.front());
inflightRequests.pop_back();
if (!inflightRequests.empty()) {
auto req = std::move(inflightRequests.front());
inflightRequests.pop_back();
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
req.resolve(std::move(parser_.response));
req.onDone();
req.resolve(std::move(parser_.response));
if (req.onDone)
req.onDone();
}
parser_.reset();
}
}
void
Connection::handleError(const char* error) {
auto req = std::move(inflightRequests.front());
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
if (!inflightRequests.empty()) {
auto req = std::move(inflightRequests.front());
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
req.reject(Error(error));
req.onDone();
req.reject(Error(error));
if (req.onDone)
req.onDone();
}
}
void
Connection::handleTimeout() {
auto req = std::move(inflightRequests.front());
inflightRequests.pop_back();
if (!inflightRequests.empty()) {
auto req = std::move(inflightRequests.front());
inflightRequests.pop_back();
timerPool_.releaseTimer(req.timer);
timerPool_.releaseTimer(req.timer);
req.onDone();
/* @API: create a TimeoutException */
req.reject(std::runtime_error("Timeout"));
if (req.onDone)
req.onDone();
/* @API: create a TimeoutException */
req.reject(std::runtime_error("Timeout"));
}
}
Async::Promise<Response>
Connection::perform(
const Http::Request& request,
......
Markdown is supported
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