From ef0db7d6643a4702c4e7058a42c6e4e73d175b87 Mon Sep 17 00:00:00 2001 From: Davide Gerhard Date: Mon, 8 Feb 2021 08:09:11 +0100 Subject: [PATCH] setsockopt to prioritize the newtwork packets --- new_protocol.c | 11 +++++++++++ old_protocol.c | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/new_protocol.c b/new_protocol.c index 64cabfe..55695e8 100644 --- a/new_protocol.c +++ b/new_protocol.c @@ -594,6 +594,17 @@ void new_protocol_init(int pixels) { int optval = 1; setsockopt(data_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); setsockopt(data_socket, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)); +#ifdef __APPLE__ + optval = 0x10; // IPTOS_LOWDELAY + if(setsockopt(data_socket, IPPROTO_IP, IP_TOS, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#else + optval = 6; + if(setsockopt(data_socket, SOL_SOCKET, SO_PRIORITY, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#endif // bind to the interface if(bind(data_socket,(struct sockaddr*)&radio->info.network.interface_address,radio->info.network.interface_length)<0) { diff --git a/old_protocol.c b/old_protocol.c index ee1cc0f..99f0a3c 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -439,6 +439,17 @@ static void open_udp_socket() { if (setsockopt(tmp, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval))<0) { perror("data_socket: SO_RCVBUF"); } +#ifdef __APPLE__ + optval = 0x10; // IPTOS_LOWDELAY + if(setsockopt(tmp, IPPROTO_IP, IP_TOS, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#else + optval = 6; + if(setsockopt(tmp, SOL_SOCKET, SO_PRIORITY, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#endif // // set a timeout for receive @@ -502,6 +513,17 @@ static void open_tcp_socket() { if (setsockopt(tmp, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval))<0) { perror("tcp_socket: SO_RCVBUF"); } +#ifdef __APPLE__ + optval = 0x10; // IPTOS_LOWDELAY + if(setsockopt(tmp, IPPROTO_IP, IP_TOS, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#else + optval = 6; + if(setsockopt(tmp, SOL_SOCKET, SO_PRIORITY, &optval, sizeof(optval))<0) { + perror("data_socket: SO_PRIORITY"); + } +#endif tcp_socket=tmp; g_print("TCP socket established: %d\n", tcp_socket); } -- 2.45.2