From abacfceb23fc41d0b632a7985c2291c02225b432 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 23 Aug 2023 19:38:07 +0300 Subject: libtox synced with their master, it could help to fix #3649 --- protocols/Tox/libtox/src/toxcore/TCP_server.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'protocols/Tox/libtox/src/toxcore/TCP_server.c') diff --git a/protocols/Tox/libtox/src/toxcore/TCP_server.c b/protocols/Tox/libtox/src/toxcore/TCP_server.c index f571a312d2..ecd557d1b2 100644 --- a/protocols/Tox/libtox/src/toxcore/TCP_server.c +++ b/protocols/Tox/libtox/src/toxcore/TCP_server.c @@ -166,7 +166,7 @@ static void free_accepted_connection_array(TCP_Server *tcp_server) tcp_server->size_accepted_connections = 0; } -/** +/** * @return index corresponding to connection with peer on success * @retval -1 on failure. */ @@ -388,7 +388,7 @@ non_null() static int send_routing_response(const Logger *logger, TCP_Secure_Connection *con, uint8_t rpid, const uint8_t *public_key) { - uint8_t data[1 + 1 + CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t data[2 + CRYPTO_PUBLIC_KEY_SIZE]; data[0] = TCP_PACKET_ROUTING_RESPONSE; data[1] = rpid; memcpy(data + 2, public_key, CRYPTO_PUBLIC_KEY_SIZE); @@ -1033,12 +1033,15 @@ TCP_Server *new_TCP_server(const Logger *logger, const Random *rng, const Networ non_null() static void do_TCP_accept_new(TCP_Server *tcp_server) { - for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) { - Socket sock; + for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) { + + for (uint32_t connection_idx = 0; connection_idx < MAX_INCOMING_CONNECTIONS; ++connection_idx) { + const Socket sock = net_accept(tcp_server->ns, tcp_server->socks_listening[sock_idx]); - do { - sock = net_accept(tcp_server->ns, tcp_server->socks_listening[i]); - } while (accept_connection(tcp_server, sock) != -1); + if (accept_connection(tcp_server, sock) == -1) { + break; + } + } } } #endif -- cgit v1.2.3