+int
+vcl_worker_set_bapi (void)
+{
+ vcl_worker_t *wrk = vcl_worker_get_current ();
+ int i;
+
+ /* Find the first worker with the same pid */
+ for (i = 0; i < vec_len (vcm->workers); i++)
+ {
+ if (i == wrk->wrk_index)
+ continue;
+ if (vcm->workers[i].current_pid == wrk->current_pid)
+ {
+ wrk->vl_input_queue = vcm->workers[i].vl_input_queue;
+ wrk->my_client_index = vcm->workers[i].my_client_index;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+svm_msg_q_t *
+vcl_worker_ctrl_mq (vcl_worker_t * wrk)
+{
+ return wrk->ctrl_mq;
+}
+
+void
+vcl_cleanup_bapi (void)
+{
+ socket_client_main_t *scm = &socket_client_main;
+ api_main_t *am = vlibapi_get_main ();
+
+ am->my_client_index = ~0;
+ am->my_registration = 0;
+ am->vl_input_queue = 0;
+ am->msg_index_by_name_and_crc = 0;
+ scm->socket_fd = 0;
+
+ vl_client_api_unmap ();
+}
+
+int
+vcl_session_read_ready (vcl_session_t * session)
+{
+ /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+ if (PREDICT_FALSE (session->is_vep))
+ {
+ VDBG (0, "ERROR: session %u: cannot read from an epoll session!",
+ session->session_index);
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN))))
+ {
+ vcl_session_state_t state = session->session_state;
+ int rv;
+
+ rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+
+ VDBG (1, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
+ session->session_index, session->vpp_handle, state,
+ vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
+ return rv;
+ }
+
+ if (session->session_state & STATE_LISTEN)
+ return clib_fifo_elts (session->accept_evts_fifo);
+
+ if (vcl_session_is_ct (session))
+ return svm_fifo_max_dequeue_cons (session->ct_rx_fifo);
+
+ return svm_fifo_max_dequeue_cons (session->rx_fifo);
+}
+
+int
+vcl_session_write_ready (vcl_session_t * session)
+{
+ /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+ if (PREDICT_FALSE (session->is_vep))
+ {
+ VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
+ session->session_index, session->vpp_handle);
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
+ {
+ if (session->tx_fifo)
+ return svm_fifo_max_enqueue_prod (session->tx_fifo);
+ else
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (!(session->session_state & STATE_OPEN)))
+ {
+ vcl_session_state_t state = session->session_state;
+ int rv;
+
+ rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ VDBG (0, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
+ session->session_index, session->vpp_handle, state,
+ vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
+ return rv;
+ }
+
+ if (vcl_session_is_ct (session))
+ return svm_fifo_max_enqueue_prod (session->ct_tx_fifo);
+
+ return svm_fifo_max_enqueue_prod (session->tx_fifo);