hsa: fix coverity issue CID-313635
[vpp.git] / src / plugins / hs_apps / vcl / vcl_test_server.c
index 93c2444..b7731d3 100644 (file)
@@ -373,8 +373,9 @@ vts_accept_client (vcl_test_server_worker_t *wrk, int listen_fd)
   if (tp->accept (listen_fd, conn))
     return 0;
 
-  vtinf ("Got a connection -- fd = %d (0x%08x) on listener fd = %d (0x%08x)",
-        conn->fd, conn->fd, listen_fd, listen_fd);
+  if (conn->cfg.num_test_sessions < VCL_TEST_CFG_MAX_SELECT_SESS)
+    vtinf ("Got a connection -- fd = %d (0x%08x) on listener fd = %d (0x%08x)",
+          conn->fd, conn->fd, listen_fd, listen_fd);
 
   ev.events = EPOLLET | EPOLLIN;
   ev.data.u64 = conn - wrk->conn_pool;
@@ -502,18 +503,20 @@ vcl_test_server_process_opts (vcl_test_server_main_t * vsm, int argc,
        print_usage_and_exit ();
       }
 
-  if (argc < (optind + 1))
+  if (argc > (optind + 1))
     {
-      fprintf (stderr, "SERVER: ERROR: Insufficient number of arguments!\n");
+      fprintf (stderr, "Incorrect number of arguments!\n");
       print_usage_and_exit ();
     }
-
-  if (sscanf (argv[optind], "%d", &v) == 1)
-    vsm->server_cfg.port = (uint16_t) v;
-  else
+  else if (argc > 1 && argc == (optind + 1))
     {
-      fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
-      print_usage_and_exit ();
+      if (sscanf (argv[optind], "%d", &v) == 1)
+       vsm->server_cfg.port = (uint16_t) v;
+      else
+       {
+         fprintf (stderr, "Invalid port (%s)!\n", argv[optind]);
+         print_usage_and_exit ();
+       }
     }
 
   vcl_test_init_endpoint_addr (vsm);
@@ -562,6 +565,7 @@ vts_handle_ctrl_cfg (vcl_test_server_worker_t *wrk, vcl_test_cfg_t *rx_cfg,
       wrk->nfds--;
       if (wrk->nfds)
        vts_wrk_cleanup_all (wrk);
+      vcl_server_main.ctrl = 0;
       break;
 
     default:
@@ -586,7 +590,7 @@ vts_worker_init (vcl_test_server_worker_t * wrk)
 
   vtinf ("Initializing worker ...");
 
-  conn_pool_expand (wrk, VCL_TEST_CFG_MAX_TEST_SESS + 1);
+  conn_pool_expand (wrk, VCL_TEST_CFG_INIT_TEST_SESS + 1);
   if (wrk->wrk_index)
     if (vppcom_worker_register ())
       vtfail ("vppcom_worker_register()", 1);
@@ -675,13 +679,13 @@ vts_worker_loop (void *arg)
           */
          if (ep_evts[i].events & (EPOLLHUP | EPOLLRDHUP))
            {
-             vts_session_cleanup (conn);
-             wrk->nfds--;
-             if (!wrk->nfds)
+             if (conn == vsm->ctrl)
                {
-                 vtinf ("All client connections closed\n");
-                 goto done;
+                 vtinf ("ctrl session went away");
+                 vsm->ctrl = 0;
                }
+             vts_session_cleanup (conn);
+             wrk->nfds--;
              continue;
            }
 
@@ -699,6 +703,10 @@ vts_worker_loop (void *arg)
              vsm->ctrl = vts_accept_ctrl (wrk, vsm->ctrl_listen_fd);
              continue;
            }
+
+         /* at this point ctrl session must be valid */
+         ASSERT (vsm->ctrl);
+
          if (ep_evts[i].data.u32 == VCL_TEST_DATA_LISTENER)
            {
              conn = vts_accept_client (wrk, wrk->listener.fd);
@@ -854,6 +862,8 @@ main (int argc, char **argv)
       vsm->workers[i].wrk_index = i;
       rv = pthread_create (&vsm->workers[i].thread_handle, NULL,
                           vts_worker_loop, (void *) &vsm->workers[i]);
+      if (rv)
+       vtfail ("pthread_create()", rv);
     }
 
   vts_worker_loop (&vsm->workers[0]);