asio: client: Call error_cb on error occurred in do_read and do_write
Fixes GH-207
This commit is contained in:
parent
a8ea86cfe5
commit
5c2ca28706
|
@ -89,10 +89,7 @@ void session_impl::connected(tcp::resolver::iterator endpoint_it) {
|
|||
}
|
||||
|
||||
void session_impl::not_connected(const boost::system::error_code &ec) {
|
||||
auto &error_cb = on_error();
|
||||
if (error_cb) {
|
||||
error_cb(ec);
|
||||
}
|
||||
call_error_cb(ec);
|
||||
}
|
||||
|
||||
void session_impl::on_connect(connect_cb cb) { connect_cb_ = std::move(cb); }
|
||||
|
@ -103,6 +100,14 @@ const connect_cb &session_impl::on_connect() const { return connect_cb_; }
|
|||
|
||||
const error_cb &session_impl::on_error() const { return error_cb_; }
|
||||
|
||||
void session_impl::call_error_cb(const boost::system::error_code &ec) {
|
||||
auto &error_cb = on_error();
|
||||
if (!error_cb) {
|
||||
return;
|
||||
}
|
||||
error_cb(ec);
|
||||
}
|
||||
|
||||
namespace {
|
||||
int on_begin_headers_callback(nghttp2_session *session,
|
||||
const nghttp2_frame *frame, void *user_data) {
|
||||
|
@ -308,10 +313,7 @@ bool session_impl::setup_session() {
|
|||
|
||||
auto rv = nghttp2_session_client_new(&session_, callbacks, this);
|
||||
if (rv != 0) {
|
||||
auto &error_cb = on_error();
|
||||
if (error_cb) {
|
||||
error_cb(make_error_code(static_cast<nghttp2_error>(rv)));
|
||||
}
|
||||
call_error_cb(make_error_code(static_cast<nghttp2_error>(rv)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -528,6 +530,7 @@ void session_impl::do_read() {
|
|||
std::size_t bytes_transferred) {
|
||||
if (ec) {
|
||||
if (ec.value() == boost::asio::error::operation_aborted) {
|
||||
call_error_cb(ec);
|
||||
shutdown_socket();
|
||||
}
|
||||
return;
|
||||
|
@ -540,6 +543,8 @@ void session_impl::do_read() {
|
|||
nghttp2_session_mem_recv(session_, rb_.data(), bytes_transferred);
|
||||
|
||||
if (rv != static_cast<ssize_t>(bytes_transferred)) {
|
||||
call_error_cb(make_error_code(
|
||||
static_cast<nghttp2_error>(rv < 0 ? rv : NGHTTP2_ERR_PROTO)));
|
||||
shutdown_socket();
|
||||
return;
|
||||
}
|
||||
|
@ -577,6 +582,7 @@ void session_impl::do_write() {
|
|||
const uint8_t *data;
|
||||
auto n = nghttp2_session_mem_send(session_, &data);
|
||||
if (n < 0) {
|
||||
call_error_cb(make_error_code(static_cast<nghttp2_error>(n)));
|
||||
shutdown_socket();
|
||||
return;
|
||||
}
|
||||
|
@ -606,6 +612,8 @@ void session_impl::do_write() {
|
|||
|
||||
write_socket([this](const boost::system::error_code &ec, std::size_t n) {
|
||||
if (ec) {
|
||||
call_error_cb(ec);
|
||||
shutdown_socket();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ protected:
|
|||
private:
|
||||
bool should_stop() const;
|
||||
bool setup_session();
|
||||
void call_error_cb(const boost::system::error_code &ec);
|
||||
|
||||
boost::asio::io_service &io_service_;
|
||||
tcp::resolver resolver_;
|
||||
|
|
Loading…
Reference in New Issue