vcl: fix disconnect from binary api
[vpp.git] / src / vcl / vcl_private.c
index 13794ea..6e887c8 100644 (file)
@@ -158,11 +158,19 @@ vcl_worker_cleanup (vcl_worker_t * wrk, u8 notify_vpp)
   clib_spinlock_lock (&vcm->workers_lock);
   if (notify_vpp)
     {
+      /* Notify vpp that the worker is going away */
       if (wrk->wrk_index == vcl_get_worker_index ())
        vcl_send_app_worker_add_del (0 /* is_add */ );
       else
        vcl_send_child_worker_del (wrk);
+
+      /* Disconnect the binary api */
+      if (vec_len (vcm->workers) == 1)
+       vppcom_disconnect_from_vpp ();
+      else
+       vl_client_send_disconnect (1 /* vpp should cleanup */ );
     }
+
   if (wrk->mqs_epfd > 0)
     close (wrk->mqs_epfd);
   hash_free (wrk->session_index_by_vpp_handles);
@@ -276,6 +284,12 @@ vcl_worker_set_bapi (void)
   return -1;
 }
 
+svm_msg_q_t *
+vcl_worker_ctrl_mq (vcl_worker_t * wrk)
+{
+  return wrk->ctrl_mq;
+}
+
 void
 vcl_segment_table_add (u64 segment_handle, u32 svm_segment_index)
 {
@@ -310,7 +324,7 @@ void
 vcl_cleanup_bapi (void)
 {
   socket_client_main_t *scm = &socket_client_main;
-  api_main_t *am = &api_main;
+  api_main_t *am = vlibapi_get_main ();
 
   am->my_client_index = ~0;
   am->my_registration = 0;