mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Adding a new connection while a lossy packet is being sent could
also cause thread related issues.
This commit is contained in:
parent
d270cf550a
commit
946a09f57b
|
@ -1268,13 +1268,26 @@ static int create_crypto_connection(Net_Crypto *c)
|
|||
return i;
|
||||
}
|
||||
|
||||
if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1)
|
||||
return -1;
|
||||
while (1) { /* TODO: is this really the best way to do this? */
|
||||
pthread_mutex_lock(&c->connections_mutex);
|
||||
|
||||
if (!c->connection_use_counter) {
|
||||
break;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
}
|
||||
|
||||
int id = -1;
|
||||
|
||||
if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == 0) {
|
||||
memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
|
||||
int id = c->crypto_connections_length;
|
||||
id = c->crypto_connections_length;
|
||||
pthread_mutex_init(&c->crypto_connections[id].mutex, NULL);
|
||||
++c->crypto_connections_length;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&c->connections_mutex);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user