From: Sven Kube Date: Tue, 13 May 2025 13:37:38 +0000 (+0200) Subject: res_audiosocket.c: Set the TCP_NODELAY socket option X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0e8f4f63b2ec2f3bb94e4dec8c9c43da332360d;p=thirdparty%2Fasterisk.git res_audiosocket.c: Set the TCP_NODELAY socket option Disable Nagle's algorithm by setting the TCP_NODELAY socket option. This reduces latency by preventing delays caused by packet buffering. --- diff --git a/res/res_audiosocket.c b/res/res_audiosocket.c index 3c4682df7f..3df074ceaa 100644 --- a/res/res_audiosocket.c +++ b/res/res_audiosocket.c @@ -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)) {