- return -1;
-
- mp = vl_msg_api_alloc (sizeof (*mp));
- mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_URI_REPLY);
- mp->context = app->api_context;
- if (!is_fail)
- {
- vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
- mp->server_rx_fifo = (u64) s->server_rx_fifo;
- mp->server_tx_fifo = (u64) s->server_tx_fifo;
- mp->session_thread_index = s->thread_index;
- mp->session_index = s->session_index;
- mp->session_type = s->session_type;
- mp->vpp_event_queue_address = (u64) vpp_queue;
- mp->client_event_queue_address = (u64) app->event_queue;
- mp->retval = 0;
-
- session_manager_get_segment_info (s->server_segment_index, &seg_name,
- &mp->segment_size);
- mp->segment_name_length = vec_len (seg_name);
- if (mp->segment_name_length)
- clib_memcpy (mp->segment_name, seg_name, mp->segment_name_length);
- }
- else
- {
- mp->retval = VNET_API_ERROR_SESSION_CONNECT_FAIL;
- }
-
- vl_msg_api_send_shmem (q, (u8 *) & mp);
-
- /* Remove client if connect failed */
- if (is_fail)
- {
- application_del (app);
- }
- else
- {
- s->session_state = SESSION_STATE_READY;
- }
-
- return 0;
-}
-
-/**
- * Redirect a connect_uri message to the indicated server.
- * Only sent if the server has bound the related port with
- * URI_OPTIONS_FLAGS_USE_FIFO
- */
-static int
-redirect_connect_uri_callback (u32 server_api_client_index, void *mp_arg)
-{
- vl_api_connect_uri_t *mp = mp_arg;
- unix_shared_memory_queue_t *server_q, *client_q;
- vlib_main_t *vm = vlib_get_main ();
- f64 timeout = vlib_time_now (vm) + 0.5;
- int rv = 0;
-
- server_q = vl_api_client_index_to_input_queue (server_api_client_index);
-
- if (!server_q)
- {
- rv = VNET_API_ERROR_INVALID_VALUE;
- goto out;
- }
-
- client_q = vl_api_client_index_to_input_queue (mp->client_index);
- if (!client_q)
- {
- rv = VNET_API_ERROR_INVALID_VALUE_2;
- goto out;
- }
-
- /* Tell the server the client's API queue address, so it can reply */
- mp->client_queue_address = (u64) client_q;
-
- /*
- * Bounce message handlers MUST NOT block the data-plane.
- * Spin waiting for the queue lock, but
- */
-
- while (vlib_time_now (vm) < timeout)
- {
- rv =
- unix_shared_memory_queue_add (server_q, (u8 *) & mp, 1 /*nowait */ );
- switch (rv)
- {
- /* correctly enqueued */
- case 0:
- return VNET_CONNECT_REDIRECTED;
-
- /* continue spinning, wait for pthread_mutex_trylock to work */
- case -1:
- continue;
-
- /* queue stuffed, drop the msg */
- case -2:
- rv = VNET_API_ERROR_QUEUE_FULL;
- goto out;
- }
- }
-out:
- /* Dispose of the message */
- vl_msg_api_free (mp);
- return rv;
-}
-
-static u64
-make_session_handle (stream_session_t * s)
-{
- return (u64) s->session_index << 32 | (u64) s->thread_index;
-}
-
-static int
-send_session_accept_callback (stream_session_t * s)
-{
- vl_api_accept_sock_t *mp;
- unix_shared_memory_queue_t *q, *vpp_queue;
- application_t *server = application_get (s->app_index);
-
- q = vl_api_client_index_to_input_queue (server->api_client_index);
- vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
-
- if (!q)
- return -1;