From 6d1caf91147ee8676b57216ca891af0f44d7a074 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Thu, 4 Jan 2018 12:17:10 -0800 Subject: sock api: add first msg id retrieval function Change-Id: I2032b5fc8e1904005b8eb871b9be06d025ed9b71 Signed-off-by: Florin Coras --- src/vlibmemory/memory_client.c | 44 ++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/vlibmemory/memory_client.c') diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c index c7ae13963c9..c47f25e6e3d 100644 --- a/src/vlibmemory/memory_client.c +++ b/src/vlibmemory/memory_client.c @@ -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: -- cgit 1.2.3-korg