]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_audiosocket: fix temporarily unavailable
authorRoman Pertsev <roman.percev@gmail.com>
Tue, 7 Oct 2025 09:49:12 +0000 (12:49 +0300)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 30 Oct 2025 16:05:57 +0000 (16:05 +0000)
Operations on non-blocking sockets may return a resource temporarily unavailable error (EAGAIN or EWOULDBLOCK). This is not a fatal error but a normal condition indicating that the operation would block.

This patch corrects the handling of this case. Instead of incorrectly treating it as a reason to terminate the connection, the code now waits for data to arrive on the socket.

res/res_audiosocket.c

index 0381fd9493fe5c5d11bba481350bee1ede1c7e4a..48bfc1f14521bf8bb1d610c4a8a6623f30f48d02 100644 (file)
@@ -297,10 +297,29 @@ struct ast_frame *ast_audiosocket_receive_frame_with_hangup(const int svc,
                *hangup = 0;
        }
 
-       n = read(svc, &header, 3);
-       if (n == -1) {
-               ast_log(LOG_WARNING, "Failed to read header from AudioSocket because: %s\n", strerror(errno));
-               return NULL;
+       while (i < 3) {
+               n = read(svc, header, 3);
+               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_debug(1, "Poll timed out while waiting for header data\n");
+                                       continue;
+                               } else {
+                                       ast_log(LOG_WARNING, "Poll error: %s\n", strerror(errno));
+                               }
+                       }
+
+                       ast_log(LOG_ERROR, "Failed to read header from AudioSocket because: %s\n", strerror(errno));
+                       return NULL;
+               }
+               if (n == 0) {
+                       break;
+               }
+               i += n;
        }
 
        if (n == 0 || *kind == AST_AUDIOSOCKET_KIND_HANGUP) {