Skip to content
Snippets Groups Projects
Commit 432f3874 authored by Seva's avatar Seva Committed by Adrien Béraud
Browse files

http: ensure conn callbacks are always invoked

parent 3abb9114
No related branches found
No related tags found
No related merge requests found
...@@ -163,6 +163,8 @@ Connection::is_open() ...@@ -163,6 +163,8 @@ Connection::is_open()
return ssl_socket_->is_open(); return ssl_socket_->is_open();
else if (socket_) else if (socket_)
return socket_->is_open(); return socket_->is_open();
else
return false;
} }
bool bool
...@@ -234,6 +236,8 @@ Connection::async_connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, Conn ...@@ -234,6 +236,8 @@ Connection::async_connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, Conn
asio::async_connect(ssl_socket_->lowest_layer(), std::move(endpoints), cb); asio::async_connect(ssl_socket_->lowest_layer(), std::move(endpoints), cb);
else if (socket_) else if (socket_)
asio::async_connect(*socket_, std::move(endpoints), cb); asio::async_connect(*socket_, std::move(endpoints), cb);
else if (cb)
cb(asio::error::operation_aborted, {});
} }
void void
...@@ -258,6 +262,8 @@ Connection::async_handshake(HandlerCb cb) ...@@ -258,6 +262,8 @@ Connection::async_handshake(HandlerCb cb)
}); });
else if (socket_) else if (socket_)
cb(asio::error::no_protocol_option); cb(asio::error::no_protocol_option);
else if (cb)
cb(asio::error::operation_aborted);
} }
void void
...@@ -269,6 +275,8 @@ Connection::async_write(BytesHandlerCb cb) ...@@ -269,6 +275,8 @@ Connection::async_write(BytesHandlerCb cb)
asio::async_write(*ssl_socket_, write_buf_, cb); asio::async_write(*ssl_socket_, write_buf_, cb);
else if (socket_) else if (socket_)
asio::async_write(*socket_, write_buf_, cb); asio::async_write(*socket_, write_buf_, cb);
else if (cb)
cb(asio::error::operation_aborted, 0);
} }
void void
...@@ -280,6 +288,8 @@ Connection::async_read_until(const char* delim, BytesHandlerCb cb) ...@@ -280,6 +288,8 @@ Connection::async_read_until(const char* delim, BytesHandlerCb cb)
asio::async_read_until(*ssl_socket_, read_buf_, delim, cb); asio::async_read_until(*ssl_socket_, read_buf_, delim, cb);
else if (socket_) else if (socket_)
asio::async_read_until(*socket_, read_buf_, delim, cb); asio::async_read_until(*socket_, read_buf_, delim, cb);
else if (cb)
cb(asio::error::operation_aborted, 0);
} }
void void
...@@ -291,6 +301,8 @@ Connection::async_read(const size_t bytes, BytesHandlerCb cb) ...@@ -291,6 +301,8 @@ Connection::async_read(const size_t bytes, BytesHandlerCb cb)
asio::async_read(*ssl_socket_, read_buf_, asio::transfer_exactly(bytes), cb); asio::async_read(*ssl_socket_, read_buf_, asio::transfer_exactly(bytes), cb);
else if (socket_) else if (socket_)
asio::async_read(*socket_, read_buf_, asio::transfer_exactly(bytes), cb); asio::async_read(*socket_, read_buf_, asio::transfer_exactly(bytes), cb);
else if (cb)
cb(asio::error::operation_aborted, 0);
} }
void void
...@@ -299,6 +311,8 @@ Connection::timeout(const std::chrono::seconds timeout, HandlerCb cb) ...@@ -299,6 +311,8 @@ Connection::timeout(const std::chrono::seconds timeout, HandlerCb cb)
if (!is_open()){ if (!is_open()){
if (logger_) if (logger_)
logger_->e("[http:client] [connection:%i] closed, can't timeout", id_); logger_->e("[http:client] [connection:%i] closed, can't timeout", id_);
if (cb)
cb(asio::error::operation_aborted);
return; return;
} }
if (!timeout_timer_) if (!timeout_timer_)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment