sock api: allow to start client with no rx_thread

Change-Id: Ia30ff1e62304e65f27497ce05f8e40631c06d69e
Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
diff --git a/src/tests/vnet/session/tcp_echo.c b/src/tests/vnet/session/tcp_echo.c
index 58e29bd..bd05345 100644
--- a/src/tests/vnet/session/tcp_echo.c
+++ b/src/tests/vnet/session/tcp_echo.c
@@ -482,7 +482,7 @@
 	  return -1;
 	}
 
-      if (vl_socket_client_init_shm (0))
+      if (vl_socket_client_init_shm (0, 1 /* want_pthread */ ))
 	{
 	  clib_warning ("init shm api failed");
 	  return -1;
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index d35c19e..5ddbb57 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -22025,7 +22025,7 @@
   config[6].count = 128;
   config[6].size = sizeof (uword);
 
-  rv = vl_socket_client_init_shm (config);
+  rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
   if (!rv)
     vam->client_index_invalid = 1;
   return rv;
diff --git a/src/vcl/vcl_bapi.c b/src/vcl/vcl_bapi.c
index debfb8f..b7f47d8 100644
--- a/src/vcl/vcl_bapi.c
+++ b/src/vcl/vcl_bapi.c
@@ -679,7 +679,7 @@
 	  return VPPCOM_ECONNREFUSED;
 	}
 
-      if (vl_socket_client_init_shm (0))
+      if (vl_socket_client_init_shm (0, 1 /* want_pthread */ ))
 	{
 	  VERR ("app (%s) init shm failed!", app_name);
 	  return VPPCOM_ECONNREFUSED;
diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c
index 3add39a..fb11734 100644
--- a/src/vlibmemory/memory_client.c
+++ b/src/vlibmemory/memory_client.c
@@ -468,6 +468,16 @@
 				   0 /* dont map */ );
 }
 
+int
+vl_client_connect_to_vlib_no_rx_pthread_no_map (const char *svm_name,
+						const char *client_name,
+						int rx_queue_size)
+{
+  return connect_to_vlib_internal (svm_name, client_name, rx_queue_size,
+				   0 /* want pthread */ ,
+				   0 /* dont map */ );
+}
+
 static void
 disconnect_from_vlib_internal (u8 do_unmap)
 {
diff --git a/src/vlibmemory/memory_client.h b/src/vlibmemory/memory_client.h
index 6aaf6d7..8400d96 100644
--- a/src/vlibmemory/memory_client.h
+++ b/src/vlibmemory/memory_client.h
@@ -35,6 +35,9 @@
 int vl_client_connect_to_vlib_no_map (const char *svm_name,
 				      const char *client_name,
 				      int rx_queue_size);
+int vl_client_connect_to_vlib_no_rx_pthread_no_map (const char *svm_name,
+						    const char *client_name,
+						    int rx_queue_size);
 void vl_client_install_client_message_handlers (void);
 u8 vl_mem_client_is_connected (void);
 
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index 38bcc2a..ca1e535 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -304,8 +304,18 @@
 
   new_name = format (0, "%v[shm]%c", scm->name, 0);
   vl_client_install_client_message_handlers ();
-  vl_client_connect_to_vlib_no_map ("pvt", (char *) new_name,
-				    32 /* input_queue_length */ );
+  if (scm->want_shm_pthread)
+    {
+      vl_client_connect_to_vlib_no_map ("pvt", (char *) new_name,
+					32 /* input_queue_length */ );
+    }
+  else
+    {
+      vl_client_connect_to_vlib_no_rx_pthread_no_map ("pvt",
+						      (char *) new_name, 32
+						      /* input_queue_length */
+	);
+    }
   vl_socket_client_enable_disable (0);
   vec_free (new_name);
 }
@@ -402,13 +412,16 @@
 }
 
 int
-vl_socket_client_init_shm (vl_api_shm_elem_config_t * config)
+vl_socket_client_init_shm (vl_api_shm_elem_config_t * config,
+			   int want_pthread)
 {
   socket_client_main_t *scm = &socket_client_main;
   vl_api_sock_init_shm_t *mp;
   int rv, i;
   u64 *cfg;
 
+  scm->want_shm_pthread = want_pthread;
+
   mp = vl_socket_client_msg_alloc (sizeof (*mp) +
 				   vec_len (config) * sizeof (u64));
   clib_memset (mp, 0, sizeof (*mp));
diff --git a/src/vlibmemory/socket_client.h b/src/vlibmemory/socket_client.h
index 46e2c86..68cd0f2 100644
--- a/src/vlibmemory/socket_client.h
+++ b/src/vlibmemory/socket_client.h
@@ -40,6 +40,8 @@
   u8 *name;
   clib_time_t clib_time;
   ssvm_private_t memfd_segment;
+
+  int want_shm_pthread;
 } socket_client_main_t;
 
 extern socket_client_main_t socket_client_main;
@@ -53,7 +55,8 @@
 int vl_socket_client_write (void);
 void vl_socket_client_enable_disable (int enable);
 void *vl_socket_client_msg_alloc (int nbytes);
-int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config);
+int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config,
+			       int want_pthread);
 clib_error_t *vl_socket_client_recv_fd_msg (int fds[], int n_fds, u32 wait);
 
 #endif /* SRC_VLIBMEMORY_SOCKET_CLIENT_H_ */