]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_audiosocket.c: Add retry mechanism for reading data from AudioSocket
authorSven Kube <mail@sven-kube.de>
Tue, 13 May 2025 14:01:32 +0000 (16:01 +0200)
committerGeorge Joseph <gjoseph@sangoma.com>
Thu, 26 Jun 2025 18:15:04 +0000 (12:15 -0600)
The added retry mechanism addresses an issue that arises when fragmented TCP
packets are received, each containing only a portion of an AudioSocket packet.
This situation can occur if the external service sending the AudioSocket data
has Nagle's algorithm enabled.

(cherry picked from commit 0f414f6a9444010daf7986bfd9739a63e6e2be96)

res/res_audiosocket.c

index 3df074ceaa7b2c0763072fa76a003b11456b650f..daf3e5903d444687cbc828448eb80beee05c8ab3 100644 (file)
@@ -315,6 +315,18 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc,
        while (i < *length) {
                n = read(svc, data + i, *length - i);
                if (n == -1) {
+                       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                               int poll_result = ast_wait_for_input(svc, 5);
+
+                               if (poll_result == 1) {
+                                       continue;
+                               } else if (poll_result == 0) {
+                                       ast_log(LOG_WARNING, "Poll timed out while waiting for data\n");
+                               } else {
+                                       ast_log(LOG_WARNING, "Poll error: %s\n", strerror(errno));
+                               }
+                       }
+
                        ast_log(LOG_ERROR, "Failed to read payload from AudioSocket: %s\n", strerror(errno));
                        ret = -1;
                        break;