api: socket client connect set to blocking 28/32428/3
authorFlorin Coras <fcoras@cisco.com>
Mon, 24 May 2021 15:58:15 +0000 (08:58 -0700)
committerOle Tr�an <otroan@employees.org>
Wed, 26 May 2021 07:37:06 +0000 (07:37 +0000)
Binary api client must otherwise check the returned error and if it was
EAGAIN/EINPROGRESS poll for connect completion.

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I89845b1a59b9fa2ab0968029435ceb203bfa8f6c

src/vlibmemory/socket_client.c
src/vppinfra/socket.c

index 530a996..69126f8 100644 (file)
@@ -462,7 +462,7 @@ vl_socket_client_connect_internal (socket_client_main_t * scm,
 
   sock = &scm->client_socket;
   sock->config = socket_path;
-  sock->flags = CLIB_SOCKET_F_IS_CLIENT | CLIB_SOCKET_F_NON_BLOCKING_CONNECT;
+  sock->flags = CLIB_SOCKET_F_IS_CLIENT;
 
   if ((error = clib_socket_init (sock)))
     {
index 3271393..1d8b2ca 100644 (file)
@@ -518,6 +518,14 @@ clib_socket_init (clib_socket_t * s)
                                          s->fd, s->config);
          goto done;
        }
+      /* Connect was blocking so set fd to non-blocking now */
+      if (!(s->flags & CLIB_SOCKET_F_NON_BLOCKING_CONNECT) &&
+         fcntl (s->fd, F_SETFL, O_NONBLOCK) < 0)
+       {
+         error = clib_error_return_unix (0, "fcntl NONBLOCK2 (fd %d, '%s')",
+                                         s->fd, s->config);
+         goto done;
+       }
     }
 
   return error;