evt->rpc_args.fp = data;
evt->rpc_args.arg = args;
break;
+ case SESSION_IO_EVT_RX:
case SESSION_IO_EVT_TX:
case SESSION_IO_EVT_TX_FLUSH:
case SESSION_IO_EVT_BUILTIN_RX:
session_program_transport_close (session_t * s)
{
u32 thread_index = vlib_get_thread_index ();
+ session_evt_elt_t *elt;
session_worker_t *wrk;
- session_event_t *evt;
/* If we are in the handler thread, or being called with the worker barrier
* held, just append a new event to pending disconnects vector. */
if (vlib_thread_is_main_w_barrier () || thread_index == s->thread_index)
{
wrk = session_main_get_worker (s->thread_index);
- vec_add2 (wrk->pending_disconnects, evt, 1);
- clib_memset (evt, 0, sizeof (*evt));
- evt->session_handle = session_handle (s);
- evt->event_type = SESSION_CTRL_EVT_CLOSE;
+ elt = session_evt_elt_alloc (wrk);
+ clib_memset (&elt->evt, 0, sizeof (session_event_t));
+ elt->evt.session_handle = session_handle (s);
+ elt->evt.event_type = SESSION_CTRL_EVT_CLOSE;
+ session_evt_add_pending_disconnects (wrk, elt);
}
else
session_send_ctrl_evt_to_thread (s, SESSION_CTRL_EVT_CLOSE);
pool_put (session_main.wrk[s->thread_index].sessions, s);
}
+static void
+session_cleanup_notify (session_t * s, session_cleanup_ntf_t ntf)
+{
+ app_worker_t *app_wrk;
+
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (!app_wrk)
+ return;
+ app_worker_cleanup_notify (app_wrk, s, ntf);
+}
+
void
session_free_w_fifos (session_t * s)
{
+ session_cleanup_notify (s, SESSION_CLEANUP_SESSION);
segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo);
session_free (s);
}
if (!(s = session_get_if_valid (tc->s_index, tc->thread_index)))
return;
- /* Make sure we don't try to send anything more */
- svm_fifo_dequeue_drop_all (s->tx_fifo);
-
switch (s->session_state)
{
case SESSION_STATE_CREATED:
break;
case SESSION_STATE_ACCEPTING:
case SESSION_STATE_TRANSPORT_CLOSING:
+ case SESSION_STATE_CLOSING:
/* If transport finishes or times out before we get a reply
* from the app, mark transport as closed and wait for reply
* before removing the session. Cleanup session table in advance
* are assumed to have been removed from the lookup table */
session_lookup_del_session (s);
s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
+ session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
+ svm_fifo_dequeue_drop_all (s->tx_fifo);
break;
- case SESSION_STATE_CLOSING:
- case SESSION_STATE_CLOSED_WAITING:
+ case SESSION_STATE_APP_CLOSED:
/* Cleanup lookup table as transport needs to still be valid.
* Program transport close to ensure that all session events
* have been cleaned up. Once transport close is called, the
* session is just removed because both transport and app have
* confirmed the close*/
session_lookup_del_session (s);
- s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
+ s->session_state = SESSION_STATE_CLOSED;
+ session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
+ svm_fifo_dequeue_drop_all (s->tx_fifo);
session_program_transport_close (s);
break;
case SESSION_STATE_TRANSPORT_CLOSED:
break;
case SESSION_STATE_CLOSED:
+ session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
session_delete (s);
break;
default:
clib_warning ("session state %u", s->session_state);
+ session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT);
session_delete (s);
break;
}
}
/**
- * Notification from transport that session can be closed
+ * Notification from transport that it is closed
*
- * Should be called by transport only if it was closed with non-empty
- * tx fifo and once it decides to begin the closing procedure prior to
- * issuing a delete notify. This gives the chance to the session layer
- * to cleanup any outstanding events.
+ * Should be called by transport, prior to calling delete notify, once it
+ * knows that no more data will be exchanged. This could serve as an
+ * early acknowledgment of an active close especially if transport delete
+ * can be delayed a long time, e.g., tcp time-wait.
*/
void
session_transport_closed_notify (transport_connection_t * tc)
{
+ app_worker_t *app_wrk;
session_t *s;
if (!(s = session_get_if_valid (tc->s_index, tc->thread_index)))
{
session_transport_closing_notify (tc);
svm_fifo_dequeue_drop_all (s->tx_fifo);
+ s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
}
/* If app close has not been received or has not yet resulted in
* a transport close, only mark the session transport as closed */
session_lookup_del_session (s);
s->session_state = SESSION_STATE_TRANSPORT_CLOSED;
}
- else
+ /* In all closing states but transport closed switch to closed */
+ else if (s->session_state != SESSION_STATE_TRANSPORT_CLOSED)
s->session_state = SESSION_STATE_CLOSED;
+
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (app_wrk)
+ app_worker_transport_closed_notify (app_wrk, s);
}
/**
sh = session_handle (s);
session_lookup_add_connection (tc, sh);
-
return app_worker_connect_notify (app_wrk, s, opaque);
}
if (!tc)
return VNET_API_ERROR_ADDRESS_NOT_IN_USE;
- session_lookup_del_connection (tc);
+ if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
+ session_lookup_del_connection (tc);
transport_stop_listen (tp, s->connection_index);
return 0;
}
* acknowledge the close */
if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED)
session_program_transport_close (s);
-
- /* Session already closed. Clear the tx fifo */
- if (s->session_state == SESSION_STATE_CLOSED)
- svm_fifo_dequeue_drop_all (s->tx_fifo);
return;
}
void
session_transport_close (session_t * s)
{
- /* If transport is already closed, just free the session */
- if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+ if (s->session_state >= SESSION_STATE_APP_CLOSED)
{
- session_free_w_fifos (s);
+ /* If transport is already closed, just free the session */
+ if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED)
+ session_free_w_fifos (s);
return;
}
- /* If tx queue wasn't drained, change state to closed waiting for transport.
- * This way, the transport, if it so wishes, can continue to try sending the
- * outstanding data (in closed state it cannot). It MUST however at one
- * point, either after sending everything or after a timeout, call delete
- * notify. This will finally lead to the complete cleanup of the session.
+ /* If the tx queue wasn't drained, the transport can continue to try
+ * sending the outstanding data (in closed state it cannot). It MUST however
+ * at one point, either after sending everything or after a timeout, call
+ * delete notify. This will finally lead to the complete cleanup of the
+ * session.
*/
- if (svm_fifo_max_dequeue_cons (s->tx_fifo))
- s->session_state = SESSION_STATE_CLOSED_WAITING;
- else
- s->session_state = SESSION_STATE_CLOSED;
+ s->session_state = SESSION_STATE_APP_CLOSED;
transport_close (session_get_transport_proto (s), s->connection_index,
s->thread_index);
for (i = 0; i < num_threads; i++)
{
wrk = &smm->wrk[i];
- vec_validate (wrk->free_event_vector, 128);
- _vec_len (wrk->free_event_vector) = 0;
- vec_validate (wrk->pending_event_vector, 128);
- _vec_len (wrk->pending_event_vector) = 0;
- vec_validate (wrk->pending_disconnects, 128);
- _vec_len (wrk->pending_disconnects) = 0;
- vec_validate (wrk->postponed_event_vector, 128);
- _vec_len (wrk->postponed_event_vector) = 0;
-
+ wrk->new_head = clib_llist_make_head (wrk->event_elts, evt_list);
+ wrk->pending_head = clib_llist_make_head (wrk->event_elts, evt_list);
+ wrk->postponed_head = clib_llist_make_head (wrk->event_elts, evt_list);
+ wrk->disconnects_head = clib_llist_make_head (wrk->event_elts,
+ evt_list);
wrk->last_vlib_time = vlib_time_now (vlib_mains[i]);
wrk->dispatch_period = 500e-6;
if (session_main.is_enabled)
return 0;
- session_node_enable_disable (is_en);
error = session_manager_main_enable (vm);
+ session_node_enable_disable (is_en);
}
else
{