- vl_api_accept_session_reply_t *rmp;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_ACCEPT_SESSION_REPLY);
- rmp->retval = htonl (retval);
- rmp->context = context;
- rmp->handle = handle;
- vl_msg_api_send_shmem (wrk->vl_input_queue, (u8 *) & rmp);
+ vppcom_cfg_t *vcl_cfg = &vcm->cfg;
+ int rv = VPPCOM_OK;
+ api_main_t *am;
+ u8 *wrk_name;
+
+ wrk_name = format (0, "%v-wrk-%u%c", vcm->app_name, wrk->wrk_index, 0);
+
+ /* Make sure api is cleaned up in case this is a connect from a
+ * forked worker */
+ vcl_bapi_cleanup ();
+
+ vlibapi_set_main (&wrk->bapi_api_ctx);
+ vlibapi_set_memory_client_main (&wrk->bapi_mem_ctx);
+
+ if (!vcl_cfg->vpp_bapi_socket_name)
+ {
+ rv = VPPCOM_EINVAL;
+ goto error;
+ }
+
+ if (vl_socket_client_connect2 (&wrk->bapi_sock_ctx,
+ (char *) vcl_cfg->vpp_bapi_socket_name,
+ (char *) wrk_name,
+ 0 /* default rx/tx buffer */ ))
+ {
+ VERR ("app (%s) socket connect failed!", wrk_name);
+ rv = VPPCOM_ECONNREFUSED;
+ goto error;
+ }
+
+ if (vl_socket_client_init_shm2 (&wrk->bapi_sock_ctx, 0,
+ 1 /* want_pthread */ ))
+ {
+ VERR ("app (%s) init shm failed!", wrk_name);
+ rv = VPPCOM_ECONNREFUSED;
+ goto error;
+ }
+ vcl_bapi_hookup ();
+
+ am = vlibapi_get_main ();
+ wrk->vl_input_queue = am->shmem_hdr->vl_input_queue;
+ wrk->api_client_handle = (u32) am->my_client_index;
+
+ VDBG (0, "app (%s) is connected to VPP!", wrk_name);
+ vcl_evt (VCL_EVT_INIT, vcm);
+
+error:
+ vec_free (wrk_name);
+ return rv;