fix closing streams if an error happens
This commit is contained in:
parent
2b78e09db2
commit
d5fb48eb5f
|
@ -81,7 +81,7 @@ namespace multigpu {
|
|||
if (!self) return;
|
||||
if (ec) {
|
||||
log_error("session ", self->_session_id, ": error sending data: ", ec.message());
|
||||
self->CloseNow();
|
||||
self->CloseNow(ec);
|
||||
} else {
|
||||
// DEBUG_ASSERT_EQ(bytes, sizeof(message_size_type) + message->size());
|
||||
}
|
||||
|
@ -200,15 +200,19 @@ namespace multigpu {
|
|||
}
|
||||
}
|
||||
|
||||
void Primary::CloseNow() {
|
||||
void Primary::CloseNow(boost::system::error_code ec) {
|
||||
_deadline.cancel();
|
||||
if (!ec)
|
||||
{
|
||||
if (_socket.is_open()) {
|
||||
boost::system::error_code ec;
|
||||
_socket.shutdown(boost::asio::socket_base::shutdown_both, ec);
|
||||
boost::system::error_code ec2;
|
||||
_socket.shutdown(boost::asio::socket_base::shutdown_both, ec2);
|
||||
_socket.close();
|
||||
_on_closed(shared_from_this());
|
||||
}
|
||||
}
|
||||
_on_closed(shared_from_this());
|
||||
log_debug("session", _session_id, "closed");
|
||||
}
|
||||
|
||||
} // namespace multigpu
|
||||
} // namespace carla
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace multigpu {
|
|||
|
||||
void StartTimer();
|
||||
|
||||
void CloseNow();
|
||||
void CloseNow(boost::system::error_code ec = boost::system::error_code());
|
||||
|
||||
friend class Listener;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace tcp {
|
|||
boost::asio::post(_strand.context(), [=]() { callback(self); });
|
||||
} else {
|
||||
log_error("session", _session_id, ": error retrieving stream id :", ec.message());
|
||||
CloseNow();
|
||||
CloseNow(ec);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace tcp {
|
|||
_is_writing = false;
|
||||
if (ec) {
|
||||
log_info("session", _session_id, ": error sending data :", ec.message());
|
||||
CloseNow();
|
||||
CloseNow(ec);
|
||||
} else {
|
||||
DEBUG_ONLY(log_debug("session", _session_id, ": successfully sent", bytes, "bytes"));
|
||||
DEBUG_ASSERT_EQ(bytes, sizeof(message_size_type) + message->size());
|
||||
|
@ -137,13 +137,16 @@ namespace tcp {
|
|||
}
|
||||
}
|
||||
|
||||
void ServerSession::CloseNow() {
|
||||
void ServerSession::CloseNow(boost::system::error_code ec) {
|
||||
_deadline.cancel();
|
||||
if (!ec)
|
||||
{
|
||||
if (_socket.is_open()) {
|
||||
boost::system::error_code ec;
|
||||
_socket.shutdown(boost::asio::socket_base::shutdown_both, ec);
|
||||
boost::system::error_code ec2;
|
||||
_socket.shutdown(boost::asio::socket_base::shutdown_both, ec2);
|
||||
_socket.close();
|
||||
}
|
||||
}
|
||||
_on_closed(shared_from_this());
|
||||
log_debug("session", _session_id, "closed");
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace tcp {
|
|||
|
||||
void StartTimer();
|
||||
|
||||
void CloseNow();
|
||||
void CloseNow(boost::system::error_code ec = boost::system::error_code());
|
||||
|
||||
friend class Server;
|
||||
|
||||
|
|
Loading…
Reference in New Issue