Fix possible thread issue.

merge-requests/28/head
Mr_Goldberg 2020-01-17 15:46:50 -05:00
parent 29e713b94c
commit e6031c7597
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
1 changed files with 13 additions and 6 deletions

View File

@ -70,6 +70,8 @@ public ISteamNetworking
std::recursive_mutex messages_mutex;
std::vector<Common_Message> messages;
std::recursive_mutex connections_edit_mutex;
std::vector<struct Steam_Networking_Connection> connections;
std::vector<struct steam_listen_socket> listen_sockets;
@ -79,11 +81,13 @@ public ISteamNetworking
bool connection_exists(CSteamID id)
{
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
return std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;}) != connections.end();
}
struct Steam_Networking_Connection *get_or_create_connection(CSteamID id)
{
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
auto conn = std::find_if(connections.begin(), connections.end(), [&id](struct Steam_Networking_Connection const& conn) { return conn.remote == id;});
if (connections.end() == conn) {
@ -98,6 +102,8 @@ struct Steam_Networking_Connection *get_or_create_connection(CSteamID id)
void remove_connection(CSteamID id)
{
{
std::lock_guard<std::recursive_mutex> lock(connections_edit_mutex);
auto conn = std::begin(connections);
while (conn != std::end(connections)) {
if (conn->remote == id) {
@ -107,6 +113,7 @@ void remove_connection(CSteamID id)
++conn;
}
}
}
//pretty sure steam also clears the entire queue of messages for that connection
{