vcl: allow non-blocking connects 10/21610/7
authorFlorin Coras <fcoras@cisco.com>
Thu, 29 Aug 2019 19:03:17 +0000 (12:03 -0700)
committerDamjan Marion <dmarion@me.com>
Fri, 30 Aug 2019 13:15:42 +0000 (13:15 +0000)
Type: feature

Change-Id: I55349f482ce6781337f747b2f0d2c0a027c3a675
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/plugins/hs_apps/vcl/sock_test_client.c
src/plugins/hs_apps/vcl/vcl_test_client.c
src/vcl/vppcom.c
src/vcl/vppcom.h

index 13227f2..ed43e7f 100644 (file)
@@ -651,14 +651,6 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
                       errno_val);
              return tsock->fd;
            }
-         if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0)
-           {
-             errno_val = errno;
-             perror ("ERROR in sock_test_connect_test_sockets()");
-             fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n",
-                      errno_val);
-             return -1;
-           }
 
 #ifdef VCL_TEST
          rv = vppcom_session_connect (tsock->fd, &scm->server_endpt);
@@ -668,9 +660,8 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
              rv = -1;
            }
 #else
-         rv =
-           connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
-                    scm->server_addr_size);
+         rv = connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
+                       scm->server_addr_size);
 #endif
          if (rv < 0)
            {
@@ -680,6 +671,14 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
                       "(errno = %d)!\n", errno_val);
              return -1;
            }
+         if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0)
+           {
+             errno_val = errno;
+             perror ("ERROR in sock_test_connect_test_sockets()");
+             fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n",
+                      errno_val);
+             return -1;
+           }
          tsock->cfg = ctrl->cfg;
          vcl_test_session_buf_alloc (tsock);
          sock_test_cfg_sync (tsock);
index b9bdd6e..55bc788 100644 (file)
@@ -123,7 +123,7 @@ vtc_quic_connect_test_sessions (vcl_test_client_worker_t * wrk)
 {
   vcl_test_client_main_t *vcm = &vcl_client_main;
   vcl_test_session_t *ts, *tq;
-  uint32_t i;
+  uint32_t i, flags, flen;
   int rv;
 
   if (wrk->cfg.num_test_sessions < 1 || wrk->cfg.num_test_sessions_perq < 1)
@@ -155,7 +155,7 @@ vtc_quic_connect_test_sessions (vcl_test_client_worker_t * wrk)
   for (i = 0; i < wrk->cfg.num_test_qsessions; i++)
     {
       tq = &wrk->qsessions[i];
-      tq->fd = vppcom_session_create (vcm->proto, 1 /* is_nonblocking */ );
+      tq->fd = vppcom_session_create (vcm->proto, 0 /* is_nonblocking */ );
       tq->session_index = i;
       if (tq->fd < 0)
        {
@@ -163,12 +163,16 @@ vtc_quic_connect_test_sessions (vcl_test_client_worker_t * wrk)
          return tq->fd;
        }
 
+      /* Connect is blocking */
       rv = vppcom_session_connect (tq->fd, &vcm->server_endpt);
       if (rv < 0)
        {
          vterr ("vppcom_session_connect()", rv);
          return rv;
        }
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (tq->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
       vtinf ("Test Qsession %d (fd %d) connected.", i, tq->fd);
     }
   wrk->n_qsessions = wrk->cfg.num_test_qsessions;
@@ -223,6 +227,7 @@ vtc_connect_test_sessions (vcl_test_client_worker_t * wrk)
   vcl_test_client_main_t *vcm = &vcl_client_main;
   vcl_test_session_t *ts;
   uint32_t n_test_sessions;
+  uint32_t flags, flen;
   int i, rv;
 
   if (vcm->proto == VPPCOM_PROTO_QUIC)
@@ -253,19 +258,23 @@ vtc_connect_test_sessions (vcl_test_client_worker_t * wrk)
   for (i = 0; i < n_test_sessions; i++)
     {
       ts = &wrk->sessions[i];
-      ts->fd = vppcom_session_create (vcm->proto, 1 /* is_nonblocking */ );
+      ts->fd = vppcom_session_create (vcm->proto, 0 /* is_nonblocking */ );
       if (ts->fd < 0)
        {
          vterr ("vppcom_session_create()", ts->fd);
          return ts->fd;
        }
 
+      /* Connect is blocking */
       rv = vppcom_session_connect (ts->fd, &vcm->server_endpt);
       if (rv < 0)
        {
          vterr ("vppcom_session_connect()", rv);
          return rv;
        }
+      flags = O_NONBLOCK;
+      flen = sizeof (flags);
+      vppcom_session_attr (ts->fd, VPPCOM_ATTR_SET_FLAGS, &flags, &flen);
       vtinf ("Test session %d (fd %d) connected.", i, ts->fd);
     }
   wrk->n_sessions = n_test_sessions;
index f56c02b..72ec4f4 100644 (file)
@@ -1590,10 +1590,14 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep)
        clib_net_to_host_u16 (session->transport.rmt_port),
        vppcom_proto_str (session->session_type));
 
+  vcl_send_session_connect (wrk, session);
+
+  if (VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK))
+    return VPPCOM_EINPROGRESS;
+
   /*
-   * Send connect request and wait for reply from vpp
+   * Wait for reply from vpp if blocking
    */
-  vcl_send_session_connect (wrk, session);
   rv = vppcom_wait_for_session_state_change (session_index, STATE_CONNECT,
                                             vcm->cfg.session_timeout);
 
@@ -2033,7 +2037,14 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
       break;
     case SESSION_CTRL_EVT_CONNECTED:
       connected_msg = (session_connected_msg_t *) e->data;
-      vcl_session_connected_handler (wrk, connected_msg);
+      sid = vcl_session_connected_handler (wrk, connected_msg);
+      if (sid == VCL_INVALID_SESSION_INDEX)
+       break;
+      if (sid < n_bits && write_map)
+       {
+         clib_bitmap_set_no_check ((uword *) write_map, sid, 1);
+         *bits_set += 1;
+       }
       break;
     case SESSION_CTRL_EVT_DISCONNECTED:
       disconnected_msg = (session_disconnected_msg_t *) e->data;
index 90bec31..6281509 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <netdb.h>
 #include <errno.h>
+#include <sys/fcntl.h>
 #include <sys/poll.h>
 #include <sys/epoll.h>
 
@@ -115,6 +116,7 @@ typedef enum
   VPPCOM_OK = 0,
   VPPCOM_EAGAIN = -EAGAIN,
   VPPCOM_EWOULDBLOCK = -EWOULDBLOCK,
+  VPPCOM_EINPROGRESS = -EINPROGRESS,
   VPPCOM_EFAULT = -EFAULT,
   VPPCOM_ENOMEM = -ENOMEM,
   VPPCOM_EINVAL = -EINVAL,