flow improvements
This commit is contained in:
+9
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user