app_worker_del_segment_notify (app_wrk, ct->segment_handle);
}
- if (!segment_manager_app_detached (sm))
- {
- app_wrk = app_worker_get (ct->server_wrk);
- app_worker_del_segment_notify (app_wrk, ct->segment_handle);
- }
-
+ /* Notify server app and free segment */
segment_manager_lock_and_del_segment (sm, seg_index);
/* Cleanup segment manager if needed. If server detaches there's a chance
clib_rwlock_writer_unlock (&cm->app_segs_lock);
}
+static void
+ct_session_force_disconnect_server (ct_connection_t *sct)
+{
+ sct->peer_index = ~0;
+ session_transport_closing_notify (&sct->connection);
+}
+
int
ct_session_connect_notify (session_t *ss, session_error_t err)
{
/* Client closed while waiting for reply from server */
if (PREDICT_FALSE (!cct))
{
- session_transport_closing_notify (&sct->connection);
- session_transport_delete_notify (&sct->connection);
- ct_connection_free (sct);
+ ct_session_force_disconnect_server (sct);
return 0;
}
goto connect_error;
/*
- * Alloc client session
+ * Alloc client session, server session assumed to be established
*/
+ ASSERT (ss->session_state >= SESSION_STATE_READY);
+
cs = session_alloc (thread_index);
ss = session_get (ss_index, thread_index);
cs->session_type = ss->session_type;
cs->listener_handle = SESSION_INVALID_HANDLE;
- cs->session_state = SESSION_STATE_CONNECTING;
+ session_set_state (cs, SESSION_STATE_CONNECTING);
cs->app_wrk_index = client_wrk->wrk_index;
cs->connection_index = cct->c_c_index;
cct->c_s_index = cs->session_index;
if ((err = app_worker_init_connected (client_wrk, cs)))
{
session_free (cs);
- session_close (ss);
+ ct_session_force_disconnect_server (sct);
err = SESSION_E_ALLOC;
goto connect_error;
}
- cs->session_state = SESSION_STATE_CONNECTING;
+ session_set_state (cs, SESSION_STATE_CONNECTING);
if (app_worker_connect_notify (client_wrk, cs, 0, opaque))
{
segment_manager_dealloc_fifos (cs->rx_fifo, cs->tx_fifo);
session_free (cs);
- session_close (ss);
+ ct_session_force_disconnect_server (sct);
goto cleanup_client;
}
cs = session_get (cct->c_s_index, cct->c_thread_index);
- cs->session_state = SESSION_STATE_READY;
+ session_set_state (cs, SESSION_STATE_READY);
return 0;
ls->tx_fifo->shr->master_session_index = ls->session_index;
ls->rx_fifo->master_thread_index = ls->thread_index;
ls->tx_fifo->master_thread_index = ls->thread_index;
- ls->rx_fifo->segment_manager = sm_index;
- ls->tx_fifo->segment_manager = sm_index;
- ls->rx_fifo->segment_index = fs_index;
- ls->tx_fifo->segment_index = fs_index;
seg_handle = segment_manager_segment_handle (sm, fs);
segment_manager_segment_reader_unlock (sm);
sct->c_is_ip4);
ss->connection_index = sct->c_c_index;
ss->listener_handle = listen_session_get_handle (ll);
- ss->session_state = SESSION_STATE_CREATED;
+ session_set_state (ss, SESSION_STATE_CREATED);
server_wrk = application_listener_select_worker (ll);
ss->app_wrk_index = server_wrk->wrk_index;
cct->client_tx_fifo->refcnt++;
cct->segment_handle = sct->segment_handle;
- ss->session_state = SESSION_STATE_ACCEPTING;
+ session_set_state (ss, SESSION_STATE_ACCEPTING);
if (app_worker_accept_notify (server_wrk, ss))
{
ct_session_connect_notify (ss, SESSION_E_REFUSED);
}
static u32
-ct_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
+ct_start_listen (u32 app_listener_index, transport_endpoint_cfg_t *tep)
{
session_endpoint_cfg_t *sep;
ct_connection_t *ct;
return SESSION_E_LOCAL_CONNECT;
}
+static inline int
+ct_close_is_reset (ct_connection_t *ct, session_t *s)
+{
+ if (ct->flags & CT_CONN_F_CLIENT)
+ return (svm_fifo_max_dequeue (ct->client_rx_fifo) > 0);
+ else
+ return (svm_fifo_max_dequeue (s->rx_fifo) > 0);
+}
+
static void
ct_session_postponed_cleanup (ct_connection_t *ct)
{
+ ct_connection_t *peer_ct;
app_worker_t *app_wrk;
session_t *s;
s = session_get (ct->c_s_index, ct->c_thread_index);
app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
+ if (peer_ct)
+ {
+ if (ct_close_is_reset (ct, s))
+ session_transport_reset_notify (&peer_ct->connection);
+ else
+ session_transport_closing_notify (&peer_ct->connection);
+ }
+ session_transport_closed_notify (&ct->connection);
+
if (ct->flags & CT_CONN_F_CLIENT)
{
if (app_wrk)
thread_index, ct_handle_cleanups, uword_to_pointer (thread_index, void *));
}
-static inline int
-ct_close_is_reset (ct_connection_t *ct, session_t *s)
-{
- if (ct->flags & CT_CONN_F_CLIENT)
- return (svm_fifo_max_dequeue (ct->client_rx_fifo) > 0);
- else
- return (svm_fifo_max_dequeue (s->rx_fifo) > 0);
-}
-
static void
ct_session_close (u32 ct_index, u32 thread_index)
{
if (peer_ct->flags & CT_CONN_F_HALF_OPEN)
{
ct_session_connect_notify (s, SESSION_E_REFUSED);
+ ct->peer_index = ~0;
}
- else if (peer_ct->c_s_index != ~0)
- {
- if (ct_close_is_reset (ct, s))
- session_transport_reset_notify (&peer_ct->connection);
- else
- session_transport_closing_notify (&peer_ct->connection);
- }
- else
+ else if (peer_ct->c_s_index == ~0)
{
/* should not happen */
clib_warning ("ct peer without session");
ct_app_rx_evt (transport_connection_t * tc)
{
ct_connection_t *ct = (ct_connection_t *) tc, *peer_ct;
- session_t *ps;
+ session_t *ps, *s;
+ s = session_get (ct->c_s_index, ct->c_thread_index);
+ if (session_has_transport (s) || s->session_state < SESSION_STATE_READY)
+ return -1;
peer_ct = ct_connection_get (ct->peer_index, tc->thread_index);
- if (!peer_ct)
+ if (!peer_ct || (peer_ct->flags & CT_CONN_F_HALF_OPEN))
return -1;
ps = session_get (peer_ct->c_s_index, peer_ct->c_thread_index);
+ if (ps->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
+ return -1;
return session_dequeue_notify (ps);
}
};
/* *INDENT-ON* */
+static inline int
+ct_session_can_tx (session_t *s)
+{
+ return (s->session_state == SESSION_STATE_READY ||
+ s->session_state == SESSION_STATE_CLOSING ||
+ s->session_state == SESSION_STATE_APP_CLOSED);
+}
+
int
ct_session_tx (session_t * s)
{
ct_connection_t *ct, *peer_ct;
session_t *peer_s;
+ if (!ct_session_can_tx (s))
+ return 0;
ct = (ct_connection_t *) session_get_transport (s);
peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
if (!peer_ct)