Skip to content

Commit

Permalink
simplify do_tcp(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudden6 committed Apr 12, 2021
1 parent c9ad4a2 commit 25a56c3
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,9 +2287,7 @@ static void do_tcp(Net_Crypto *c, void *userdata)
do_tcp_connections(c->log, c->tcp_c, userdata);
pthread_mutex_unlock(&c->tcp_mutex);

uint32_t i;

for (i = 0; i < c->crypto_connections_length; ++i) {
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
Crypto_Connection *conn = get_crypto_connection(c, i);

if (conn == nullptr) {
Expand All @@ -2300,21 +2298,15 @@ static void do_tcp(Net_Crypto *c, void *userdata)
continue;
}

bool direct_connected = 0;
bool direct_connected = false;

if (!crypto_connection_status(c, i, &direct_connected, nullptr)) {
continue;
}

if (direct_connected) {
pthread_mutex_lock(&c->tcp_mutex);
set_tcp_connection_to_status(c->tcp_c, conn->connection_number_tcp, 0);
pthread_mutex_unlock(&c->tcp_mutex);
} else {
pthread_mutex_lock(&c->tcp_mutex);
set_tcp_connection_to_status(c->tcp_c, conn->connection_number_tcp, 1);
pthread_mutex_unlock(&c->tcp_mutex);
}
pthread_mutex_lock(&c->tcp_mutex);
set_tcp_connection_to_status(c->tcp_c, conn->connection_number_tcp, !direct_connected);
pthread_mutex_unlock(&c->tcp_mutex);
}
}

Expand Down

0 comments on commit 25a56c3

Please sign in to comment.