diff options
Diffstat (limited to 'src/vnet/session/session_api.c')
-rwxr-xr-x | src/vnet/session/session_api.c | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index 2d20d5f697b..2decd9b8a2e 100755 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -505,10 +505,10 @@ mq_send_session_accepted_cb (stream_session_t * s) return 0; } -static void -mq_send_session_disconnected_cb (stream_session_t * s) +static inline void +mq_send_session_close_evt (app_worker_t * app_wrk, session_handle_t sh, + session_evt_type_t evt_type) { - app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); svm_msg_q_msg_t _msg, *msg = &_msg; session_disconnected_msg_t *mp; svm_msg_q_t *app_mq; @@ -519,53 +519,72 @@ mq_send_session_disconnected_cb (stream_session_t * s) return; evt = svm_msg_q_msg_data (app_mq, msg); clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; + evt->event_type = evt_type; mp = (session_disconnected_msg_t *) evt->data; - mp->handle = session_handle (s); + mp->handle = sh; mp->context = app_wrk->api_client_index; svm_msg_q_add_and_unlock (app_mq, msg); } +static inline void +mq_notify_close_subscribers (u32 app_index, session_handle_t sh, + svm_fifo_t * f, session_evt_type_t evt_type) +{ + app_worker_t *app_wrk; + application_t *app; + int i; + + app = application_get (app_index); + if (!app) + return; + + for (i = 0; i < f->n_subscribers; i++) + { + if (!(app_wrk = application_get_worker (app, f->subscribers[i]))) + continue; + mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED); + } +} + +static void +mq_send_session_disconnected_cb (stream_session_t * s) +{ + app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); + session_handle_t sh = session_handle (s); + + mq_send_session_close_evt (app_wrk, session_handle (s), + SESSION_CTRL_EVT_DISCONNECTED); + + if (svm_fifo_n_subscribers (s->server_rx_fifo)) + mq_notify_close_subscribers (app_wrk->app_index, sh, s->server_rx_fifo, + SESSION_CTRL_EVT_DISCONNECTED); +} + void mq_send_local_session_disconnected_cb (u32 app_wrk_index, local_session_t * ls) { app_worker_t *app_wrk = app_worker_get (app_wrk_index); - svm_msg_q_msg_t _msg, *msg = &_msg; - session_disconnected_msg_t *mp; - svm_msg_q_t *app_mq; - session_event_t *evt; + session_handle_t sh = application_local_session_handle (ls); - app_mq = app_wrk->event_queue; - if (mq_try_lock_and_alloc_msg (app_mq, msg)) - return; - evt = svm_msg_q_msg_data (app_mq, msg); - clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_DISCONNECTED; - mp = (session_disconnected_msg_t *) evt->data; - mp->handle = application_local_session_handle (ls); - mp->context = app_wrk->api_client_index; - svm_msg_q_add_and_unlock (app_mq, msg); + mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED); + + if (svm_fifo_n_subscribers (ls->server_rx_fifo)) + mq_notify_close_subscribers (app_wrk->app_index, sh, ls->server_rx_fifo, + SESSION_CTRL_EVT_DISCONNECTED); } static void mq_send_session_reset_cb (stream_session_t * s) { - app_worker_t *app = app_worker_get (s->app_wrk_index); - svm_msg_q_msg_t _msg, *msg = &_msg; - session_reset_msg_t *mp; - svm_msg_q_t *app_mq; - session_event_t *evt; + app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); + session_handle_t sh = session_handle (s); - app_mq = app->event_queue; - if (mq_try_lock_and_alloc_msg (app_mq, msg)) - return; - evt = svm_msg_q_msg_data (app_mq, msg); - clib_memset (evt, 0, sizeof (*evt)); - evt->event_type = SESSION_CTRL_EVT_RESET; - mp = (session_reset_msg_t *) evt->data; - mp->handle = session_handle (s); - svm_msg_q_add_and_unlock (app_mq, msg); + mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_RESET); + + if (svm_fifo_n_subscribers (s->server_rx_fifo)) + mq_notify_close_subscribers (app_wrk->app_index, sh, s->server_rx_fifo, + SESSION_CTRL_EVT_RESET); } static int |