Add close handling

This commit is contained in:
flamingcow
2019-05-11 21:52:49 -07:00
parent 89876f5bd6
commit ec99454756
2 changed files with 20 additions and 0 deletions

View File

@@ -20,10 +20,21 @@ Request::Request(Connection* conn)
: conn_(conn),
out_buf_(64*1024) {}
Request::~Request() {
if (on_close_) {
on_close_();
}
}
void Request::NewRequest(uint16_t request_id) {
if (on_close_) {
on_close_();
}
request_id_ = request_id;
params_.clear();
body_ = {};
on_close_ = nullptr;
out_buf_.Reset();
body_written_ = false;
}
@@ -53,6 +64,10 @@ const std::string_view& Request::GetBody() const {
return body_;
}
void Request::OnClose(const std::function<void()>& on_close) {
on_close_ = on_close;
}
void Request::WriteHeader(const std::string_view& name, const std::string_view& value) {
std::lock_guard<std::recursive_mutex> l(output_mu_);