Skip to content

Commit

Permalink
fix crash when double closing (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
WiserTixx authored Nov 30, 2024
2 parents f8d66c4 + 576d765 commit 5e13f9d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ std::string TClient::GetCarPositionRaw(int Ident) {
void TClient::Disconnect(std::string_view Reason) {
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
boost::system::error_code ec;
mSocket.shutdown(socket_base::shutdown_both, ec);
if (ec) {
beammp_debugf("Failed to shutdown client socket: {}", ec.message());
}
mSocket.close(ec);
if (ec) {
beammp_debugf("Failed to close client socket: {}", ec.message());
if (mSocket.is_open()) {
mSocket.shutdown(socket_base::shutdown_both, ec);
if (ec) {
beammp_debugf("Failed to shutdown client socket: {}", ec.message());
}
mSocket.close(ec);
if (ec) {
beammp_debugf("Failed to close client socket: {}", ec.message());
}
} else {
beammp_debug("Socket is already closed.");
}
}

Expand Down

0 comments on commit 5e13f9d

Please sign in to comment.