+static void vl_api_sock_init_shm_reply_t_handler
+ (vl_api_sock_init_shm_reply_t * mp)
+{
+ socket_client_main_t *scm = &socket_client_main;
+ ssvm_private_t *memfd = &scm->memfd_segment;
+ i32 retval = ntohl (mp->retval);
+ api_main_t *am = &api_main;
+ clib_error_t *error;
+ int my_fd = -1;
+ u8 *new_name;
+
+ if (retval)
+ {
+ clib_warning ("failed to init shmem");
+ return;
+ }
+
+ /*
+ * Check the socket for the magic fd
+ */
+ error = vl_sock_api_recv_fd_msg (scm->socket_fd, &my_fd, 1, 5);
+ if (error)
+ {
+ clib_error_report (error);
+ retval = -99;
+ return;
+ }
+
+ clib_memset (memfd, 0, sizeof (*memfd));
+ memfd->fd = my_fd;
+
+ /* Note: this closes memfd.fd */
+ retval = ssvm_slave_init_memfd (memfd);
+ if (retval)
+ clib_warning ("WARNING: segment map returned %d", retval);
+
+ /*
+ * Pivot to the memory client segment that vpp just created
+ */
+ am->vlib_rp = (void *) (memfd->requested_va + MMAP_PAGESIZE);
+ am->shmem_hdr = (void *) am->vlib_rp->user_ctx;
+
+ 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 */ );
+ vl_socket_client_enable_disable (0);
+ vec_free (new_name);
+}
+
+static void
+vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
+{
+ socket_client_main_t *scm = &socket_client_main;
+ if (!mp->response)
+ {
+ scm->socket_enable = 1;
+ scm->client_index = clib_net_to_host_u32 (mp->index);
+ }
+}
+
+#define foreach_sock_client_api_msg \
+_(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply) \
+_(SOCK_INIT_SHM_REPLY, sock_init_shm_reply) \
+
+static void
+noop_handler (void *notused)
+{
+}
+
+void
+vl_sock_client_install_message_handlers (void)
+{
+
+#define _(N,n) \
+ vl_msg_api_set_handlers(VL_API_##N, #n, \
+ vl_api_##n##_t_handler, \
+ noop_handler, \
+ vl_api_##n##_t_endian, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 1);
+ foreach_sock_client_api_msg;
+#undef _
+}
+
+int
+vl_socket_client_connect (char *socket_path, char *client_name,
+ u32 socket_buffer_size)
+{
+ socket_client_main_t *scm = &socket_client_main;
+ vl_api_sockclnt_create_t *mp;
+ clib_socket_t *sock;
+ clib_error_t *error;
+
+ /* Already connected? */
+ if (scm->socket_fd)
+ return (-2);
+
+ /* bogus call? */
+ if (socket_path == 0 || client_name == 0)
+ return (-3);
+
+ sock = &scm->client_socket;
+ sock->config = socket_path;
+ sock->flags = CLIB_SOCKET_F_IS_CLIENT
+ | CLIB_SOCKET_F_SEQPACKET | CLIB_SOCKET_F_NON_BLOCKING_CONNECT;
+
+ if ((error = clib_socket_init (sock)))