asio: Indicate EOF by passing 0 to the second parameter to data_cb
This commit is contained in:
parent
7fb7575f78
commit
ff0eaf8399
|
@ -57,8 +57,6 @@ void request::on_data(data_cb cb) const {
|
|||
return impl_->on_data(std::move(cb));
|
||||
}
|
||||
|
||||
void request::on_end(void_cb cb) const { return impl_->on_end(std::move(cb)); }
|
||||
|
||||
request_impl &request::impl() const { return *impl_; }
|
||||
|
||||
response::response() : impl_(make_unique<response_impl>()) {}
|
||||
|
@ -108,8 +106,6 @@ void request_impl::pushed(bool f) { pushed_ = f; }
|
|||
|
||||
void request_impl::on_data(data_cb cb) { on_data_cb_ = std::move(cb); }
|
||||
|
||||
void request_impl::on_end(void_cb cb) { on_end_cb_ = std::move(cb); }
|
||||
|
||||
void request_impl::stream(http2_stream *s) { stream_ = s; }
|
||||
|
||||
void request_impl::call_on_data(const uint8_t *data, std::size_t len) {
|
||||
|
@ -118,12 +114,6 @@ void request_impl::call_on_data(const uint8_t *data, std::size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
void request_impl::call_on_end() {
|
||||
if (on_end_cb_) {
|
||||
on_end_cb_();
|
||||
}
|
||||
}
|
||||
|
||||
response_impl::response_impl()
|
||||
: stream_(nullptr), status_code_(200), started_(false) {}
|
||||
|
||||
|
@ -288,7 +278,7 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
|||
}
|
||||
|
||||
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||
stream->request().impl().call_on_end();
|
||||
stream->request().impl().call_on_data(nullptr, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -300,7 +290,7 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
|
|||
handler->call_on_request(*stream);
|
||||
|
||||
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||
stream->request().impl().call_on_end();
|
||||
stream->request().impl().call_on_data(nullptr, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -62,12 +62,10 @@ public:
|
|||
bool pushed() const;
|
||||
|
||||
void on_data(data_cb cb);
|
||||
void on_end(void_cb cb);
|
||||
|
||||
void pushed(bool f);
|
||||
void stream(http2_stream *s);
|
||||
void call_on_data(const uint8_t *data, std::size_t len);
|
||||
void call_on_end();
|
||||
|
||||
private:
|
||||
http2_stream *stream_;
|
||||
|
@ -75,7 +73,6 @@ private:
|
|||
std::string method_;
|
||||
uri_ref uri_;
|
||||
data_cb on_data_cb_;
|
||||
void_cb on_end_cb_;
|
||||
bool pushed_;
|
||||
};
|
||||
|
||||
|
|
|
@ -71,6 +71,8 @@ struct uri_ref {
|
|||
std::string fragment;
|
||||
};
|
||||
|
||||
// Callback function when data is arrived. EOF is indicated by
|
||||
// passing 0 to the second parameter.
|
||||
typedef std::function<void(const uint8_t *, std::size_t)> data_cb;
|
||||
typedef std::function<void(void)> void_cb;
|
||||
typedef std::function<void(const boost::system::error_code &ec)> error_cb;
|
||||
|
|
|
@ -54,9 +54,6 @@ public:
|
|||
// Sets callback when chunk of request body is received.
|
||||
void on_data(data_cb cb) const;
|
||||
|
||||
// Sets callback when request was completed.
|
||||
void on_end(void_cb cb) const;
|
||||
|
||||
// Pushes resource denoted by |path| using |method|. The additional
|
||||
// headers can be given in |h|. request_cb will be called for
|
||||
// pushed resource later on. This function returns true if it
|
||||
|
|
Loading…
Reference in New Issue