mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 16:36:49 +00:00
fix crash which could happen when closing an invalid socket
for some reason boost::asio doesn't account for this and lets us simply die when/if this happens.
This commit is contained in:
@@ -127,6 +127,7 @@ private:
|
|||||||
std::string mDID;
|
std::string mDID;
|
||||||
int mID = -1;
|
int mID = -1;
|
||||||
std::chrono::time_point<TimeType> mLastPingTime;
|
std::chrono::time_point<TimeType> mLastPingTime;
|
||||||
|
std::mutex mDisconnectMtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns a valid client, or nullptr if no such client exists
|
// Returns a valid client, or nullptr if no such client exists
|
||||||
|
|||||||
@@ -59,7 +59,13 @@ std::string TClient::GetCarPositionRaw(int Ident) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TClient::Disconnect(std::string_view Reason) {
|
void TClient::Disconnect(std::string_view Reason) {
|
||||||
|
// we need exclusivity here in case we can't
|
||||||
|
std::unique_lock Lock(mDisconnectMtx);
|
||||||
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
|
beammp_debugf("Disconnecting client {} for reason: {}", GetID(), Reason);
|
||||||
|
if (mSocket.is_open()) {
|
||||||
|
beammp_debug("Somehow Disconnect() was called twice, ignoring");
|
||||||
|
return;
|
||||||
|
}
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
mSocket.shutdown(socket_base::shutdown_both, ec);
|
mSocket.shutdown(socket_base::shutdown_both, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
|
|||||||
Reference in New Issue
Block a user