sock api: add first msg id retrieval function 54/9954/6
authorFlorin Coras <fcoras@cisco.com>
Thu, 4 Jan 2018 20:17:10 +0000 (12:17 -0800)
committerDave Barach <openvpp@barachs.net>
Fri, 5 Jan 2018 19:01:01 +0000 (19:01 +0000)
Change-Id: I2032b5fc8e1904005b8eb871b9be06d025ed9b71
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vlibmemory/memory_client.c
src/vlibmemory/memory_vlib.c

index c7ae139..c47f25e 100644 (file)
@@ -521,19 +521,44 @@ vl_client_get_first_plugin_msg_id (const char *plugin_name)
   /* Ask the data-plane for the message-ID base of the indicated plugin */
   mm->first_msg_id_reply_ready = 0;
 
-  mp = vl_msg_api_alloc (sizeof (*mp));
-  memset (mp, 0, sizeof (*mp));
-  mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
-  mp->client_index = am->my_client_index;
-  strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);
+  /* Not using shm client */
+  if (!am->my_registration)
+    {
+      mp = vl_socket_client_msg_alloc (sizeof (*mp));
+      memset (mp, 0, sizeof (*mp));
+      mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
+      mp->client_index = am->my_client_index;
+      strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);
+
+      if (vl_socket_client_write () <= 0)
+       goto sock_err;
+      if (vl_socket_client_read (1))
+       goto sock_err;
+
+      if (mm->first_msg_id_reply_ready == 1)
+       {
+         rv = mm->first_msg_id_reply;
+         goto result;
+       }
 
-  vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp);
+    sock_err:
+      /* Restore old handler */
+      am->msg_handlers[VL_API_GET_FIRST_MSG_ID_REPLY] = old_handler;
 
-  /* Synchronously wait for the answer */
-  do
+      return -1;
+    }
+  else
     {
-      timeout = clib_time_now (&clib_time) + 1.0;
+      mp = vl_msg_api_alloc (sizeof (*mp));
+      memset (mp, 0, sizeof (*mp));
+      mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
+      mp->client_index = am->my_client_index;
+      strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);
 
+      vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp);
+
+      /* Synchronously wait for the answer */
+      timeout = clib_time_now (&clib_time) + 1.0;
       while (clib_time_now (&clib_time) < timeout)
        {
          if (mm->first_msg_id_reply_ready == 1)
@@ -547,7 +572,6 @@ vl_client_get_first_plugin_msg_id (const char *plugin_name)
 
       return rv;
     }
-  while (0);
 
 result:
 
index 8054381..345b404 100644 (file)
@@ -390,11 +390,11 @@ vl_api_memclnt_delete_t_handler (vl_api_memclnt_delete_t * mp)
     }
 }
 
-void
+static void
 vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
 {
   vl_api_get_first_msg_id_reply_t *rmp;
-  unix_shared_memory_queue_t *q;
+  vl_api_registration_t *regp;
   uword *p;
   api_main_t *am = &api_main;
   vl_api_msg_range_t *rp;
@@ -402,8 +402,8 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
   u16 first_msg_id = ~0;
   int rv = -7;                 /* VNET_API_ERROR_INVALID_VALUE */
 
-  q = vl_api_client_index_to_input_queue (mp->client_index);
-  if (!q)
+  regp = vl_api_client_index_to_registration (mp->client_index);
+  if (!regp)
     return;
 
   if (am->msg_range_by_name == 0)
@@ -416,18 +416,16 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
     goto out;
 
   rp = vec_elt_at_index (am->msg_ranges, p[0]);
-
   first_msg_id = rp->first_msg_id;
   rv = 0;
 
 out:
-
   rmp = vl_msg_api_alloc (sizeof (*rmp));
   rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
   rmp->context = mp->context;
   rmp->retval = ntohl (rv);
   rmp->first_msg_id = ntohs (first_msg_id);
-  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+  vl_msg_api_send (regp, (u8 *) rmp);
 }
 
 /**