]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_audiosocket.c: Set the TCP_NODELAY socket option
authorSven Kube <mail@sven-kube.de>
Tue, 13 May 2025 13:37:38 +0000 (15:37 +0200)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Tue, 20 May 2025 13:04:51 +0000 (13:04 +0000)
Disable Nagle's algorithm by setting the TCP_NODELAY socket option.
This reduces latency by preventing delays caused by packet buffering.

res/res_audiosocket.c

index 3c4682df7f0f9fd36c394405ccedb4099714ea0c..3df074ceaa7b2c0763072fa76a003b11456b650f 100644 (file)
@@ -140,6 +140,14 @@ const int ast_audiosocket_connect(const char *server, struct ast_channel *chan)
                        continue;
                }
 
+               /*
+                * Disable Nagle's algorithm by setting the TCP_NODELAY socket option.
+                * This reduces latency by preventing delays caused by packet buffering.
+                */
+               if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &(int){1}, sizeof(int)) < 0) {
+                       ast_log(LOG_ERROR, "Failed to set TCP_NODELAY on AudioSocket: %s\n", strerror(errno));
+               }
+
                if (ast_connect(s, &addrs[i]) && errno == EINPROGRESS) {
 
                        if (handle_audiosocket_connection(server, addrs[i], s)) {