flow improvements

This commit is contained in:
2026-04-25 16:02:39 +03:00
parent 22b669fae0
commit 4ffa6ed970
21 changed files with 150 additions and 59 deletions
+9 -2
View File
@@ -123,7 +123,7 @@ static void receive_file(int sock, const std::string& relative_path, uint64_t fi
static void* handle_client(void* socket_desc) {
int client_socket = *(int*)socket_desc;
free(socket_desc);
delete static_cast<int*>(socket_desc);
while (true) {
uint32_t filename_len = 0;
@@ -186,7 +186,11 @@ static void* accept_and_handle(void* arg) {
if (client_socket >= 0) {
g_server_client_sock.store(client_socket);
int* pclient = new (std::nothrow) int(client_socket);
if (pclient) handle_client(pclient);
if (pclient) {
handle_client(pclient);
} else {
close(client_socket);
}
g_server_client_sock.store(-1);
}
@@ -203,6 +207,9 @@ static void* broadcast_listener(void* arg) {
g_broadcast_sock.store(udp.fd);
struct timeval tv{0, 100000}; // 100ms poll so cancel is detected quickly
setsockopt(udp, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
sockaddr_in addr{};
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);