[vlc-devel] [PATCH 4/6] smb2: use new happy eyeballs API

Thomas Guillem thomas at gllm.fr
Tue Mar 2 14:52:23 UTC 2021


Connect to all resolved addresses in parallel, waiting 100ms between
each new connection.

This resolves very long timeout or error when the host resolve to IPv4
and IPv6 addresses but the samba service handle only one protocol (or a
firewall is dropping one address family).
---
 modules/access/smb2.c | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index aacd0b63a8a..d45a573e8a3 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -162,12 +162,21 @@ vlc_smb2_mainloop(stream_t *access, bool teardown)
     sys->res_done = false;
     while (sys->error_status == 0 && !sys->res_done)
     {
-        struct pollfd p_fds[1];
-        int ret;
-        p_fds[0].fd = smb2_get_fd(sys->smb2);
-        p_fds[0].events = smb2_which_events(sys->smb2);
+        int ret, smb2_timeout;
+        size_t fd_count;
+        const t_socket *fds = smb2_get_fds(sys->smb2, &fd_count, &smb2_timeout);
+        int events = smb2_which_events(sys->smb2);
 
-        if (p_fds[0].fd == -1 || (ret = poll_func(p_fds, 1, timeout)) < 0)
+        struct pollfd p_fds[fd_count];
+        for (size_t i = 0; i < fd_count; ++i)
+        {
+            p_fds[i].events = events;
+            p_fds[i].fd = fds[i];
+        }
+        if (smb2_timeout != -1)
+            timeout = smb2_timeout;
+
+        if (fds == NULL || (ret = poll_func(p_fds, fd_count, timeout)) < 0)
         {
             if (errno == EINTR)
             {
@@ -190,10 +199,21 @@ vlc_smb2_mainloop(stream_t *access, bool teardown)
             }
         }
         else if (ret == 0)
-            sys->error_status = -ETIMEDOUT;
-        else if (ret > 0 && p_fds[0].revents
-             && smb2_service(sys->smb2, p_fds[0].revents) < 0)
-            VLC_SMB2_SET_ERROR(access, "smb2_service", 1);
+        {
+            if (teardown)
+                sys->error_status = -ETIMEDOUT;
+            else if (smb2_service_fd(sys->smb2, -1, 0) < 0)
+                VLC_SMB2_SET_ERROR(access, "smb2_service", 1);
+        }
+        else
+        {
+            for (size_t i = 0; i < fd_count; ++i)
+            {
+                if (p_fds[i].revents
+                 && smb2_service_fd(sys->smb2, p_fds[i].fd, p_fds[i].revents) < 0)
+                    VLC_SMB2_SET_ERROR(access, "smb2_service", 1);
+            }
+        }
     }
 
     int ret = sys->error_status == 0 ? 0 : -1;
-- 
2.30.0



More information about the vlc-devel mailing list