aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/session.c54
-rwxr-xr-xsrc/vnet/session/session_api.c85
2 files changed, 98 insertions, 41 deletions
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index c56712bbf87..efd1d73c4a0 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -518,6 +518,30 @@ stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
return svm_fifo_dequeue_drop (s->server_tx_fifo, max_bytes);
}
+static inline int
+session_notify_subscribers (u32 app_index, stream_session_t * s,
+ 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 -1;
+
+ for (i = 0; i < f->n_subscribers; i++)
+ {
+ app_wrk = application_get_worker (app, f->subscribers[i]);
+ if (!app_wrk)
+ continue;
+ if (app_worker_lock_and_send_event (app_wrk, s, evt_type))
+ return -1;
+ }
+
+ return 0;
+}
+
/**
* Notify session peer that new data has been enqueued.
*
@@ -529,10 +553,10 @@ stream_session_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
static inline int
session_enqueue_notify (stream_session_t * s)
{
- app_worker_t *app;
+ app_worker_t *app_wrk;
- app = app_worker_get_if_valid (s->app_wrk_index);
- if (PREDICT_FALSE (!app))
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (PREDICT_FALSE (!app_wrk))
{
SESSION_DBG ("invalid s->app_index = %d", s->app_wrk_index);
return 0;
@@ -545,22 +569,36 @@ session_enqueue_notify (stream_session_t * s)
}));
/* *INDENT-ON* */
- return app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_RX);
+ if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
+ FIFO_EVENT_APP_RX)))
+ return -1;
+
+ if (PREDICT_FALSE (svm_fifo_n_subscribers (s->server_rx_fifo)))
+ return session_notify_subscribers (app_wrk->app_index, s,
+ s->server_rx_fifo, FIFO_EVENT_APP_RX);
+
+ return 0;
}
int
session_dequeue_notify (stream_session_t * s)
{
- app_worker_t *app;
+ app_worker_t *app_wrk;
- app = app_worker_get_if_valid (s->app_wrk_index);
- if (PREDICT_FALSE (!app))
+ app_wrk = app_worker_get_if_valid (s->app_wrk_index);
+ if (PREDICT_FALSE (!app_wrk))
return -1;
- if (app_worker_lock_and_send_event (app, s, FIFO_EVENT_APP_TX))
+ if (PREDICT_FALSE (app_worker_lock_and_send_event (app_wrk, s,
+ FIFO_EVENT_APP_TX)))
return -1;
+ if (PREDICT_FALSE (s->server_tx_fifo->n_subscribers))
+ return session_notify_subscribers (app_wrk->app_index, s,
+ s->server_tx_fifo, FIFO_EVENT_APP_TX);
+
svm_fifo_clear_tx_ntf (s->server_tx_fifo);
+
return 0;
}
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