Commit 0753fcd6 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

asio: Add error_code parameter to cancel()

parent a1402974
......@@ -38,7 +38,7 @@ request::request() : impl_(make_unique<request_impl>()) {}
request::~request() {}
void request::cancel() const { impl_->cancel(); }
void request::cancel(uint32_t error_code) const { impl_->cancel(error_code); }
void request::on_response(response_cb cb) const {
impl_->on_response(std::move(cb));
......
......@@ -33,7 +33,7 @@ namespace client {
request_impl::request_impl() : strm_(nullptr) {}
void request_impl::cancel() { strm_->cancel(); }
void request_impl::cancel(uint32_t error_code) { strm_->cancel(error_code); }
void request_impl::on_response(response_cb cb) { response_cb_ = std::move(cb); }
......
......@@ -43,7 +43,7 @@ public:
request_impl(const request_impl &) = delete;
request_impl &operator=(const request_impl &) = delete;
void cancel();
void cancel(uint32_t error_code);
void on_response(response_cb cb);
void call_on_response(response &res);
......
......@@ -44,11 +44,11 @@ session_impl::session_impl(boost::asio::io_service &io_service)
writing_(false), inside_callback_(false) {}
session_impl::~session_impl() {
// finish up all active stream with CANCEL error code
// finish up all active stream
for (auto &p : streams_) {
auto &strm = p.second;
auto &req = strm->request().impl();
req.call_on_close(NGHTTP2_CANCEL);
req.call_on_close(NGHTTP2_INTERNAL_ERROR);
}
nghttp2_session_del(session_);
......@@ -321,9 +321,9 @@ bool session_impl::setup_session() {
return true;
}
void session_impl::cancel(stream &strm) {
void session_impl::cancel(stream &strm, uint32_t error_code) {
nghttp2_submit_rst_stream(session_, NGHTTP2_FLAG_NONE, strm.stream_id(),
NGHTTP2_CANCEL);
error_code);
signal_write();
}
......
......@@ -53,7 +53,7 @@ public:
const connect_cb &on_connect() const;
const error_cb &on_error() const;
void cancel(stream &strm);
void cancel(stream &strm, uint32_t error_code);
std::unique_ptr<stream> create_stream();
std::unique_ptr<stream> pop_stream(int32_t stream_id);
......
......@@ -36,7 +36,7 @@ stream::stream(session_impl *sess) : sess_(sess), stream_id_(0) {
request_.impl().stream(this);
}
void stream::cancel() { sess_->cancel(*this); }
void stream::cancel(uint32_t error_code) { sess_->cancel(*this, error_code); }
void stream::stream_id(int32_t stream_id) { stream_id_ = stream_id; }
......
......@@ -44,7 +44,7 @@ public:
stream(const stream &) = delete;
stream &operator=(const stream &) = delete;
void cancel();
void cancel(uint32_t error_code);
void stream_id(int32_t stream_id);
int32_t stream_id() const;
......
......@@ -65,7 +65,7 @@ void response::end(read_cb cb) const { impl_->end(std::move(cb)); }
void response::on_close(close_cb cb) const { impl_->on_close(std::move(cb)); }
void response::cancel() const { impl_->cancel(); }
void response::cancel(uint32_t error_code) const { impl_->cancel(error_code); }
const response *response::push(boost::system::error_code &ec,
std::string method, std::string path,
......@@ -145,10 +145,10 @@ void response_impl::call_on_close(uint32_t error_code) {
}
}
void response_impl::cancel() {
void response_impl::cancel(uint32_t error_code) {
auto handler = stream_->handler();
handler->stream_error(stream_->get_stream_id(), NGHTTP2_CANCEL);
handler->stream_error(stream_->get_stream_id(), error_code);
}
void response_impl::start_response() {
......
......@@ -79,7 +79,7 @@ public:
void on_close(close_cb cb);
void resume();
void cancel();
void cancel(uint32_t error_code);
response *push(boost::system::error_code &ec, std::string method,
std::string raw_path_query, header_map h = {}) const;
......
......@@ -72,7 +72,7 @@ public:
void on_push(request_cb cb) const;
void on_close(close_cb cb) const;
void cancel() const;
void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const;
const std::string &method() const;
......
......@@ -80,7 +80,7 @@ public:
void on_close(close_cb cb) const;
void cancel() const;
void cancel(uint32_t error_code = NGHTTP2_INTERNAL_ERROR) const;
// Resumes deferred response.
void resume() const;
......
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