session: send tx events when data is dequeued

Change-Id: Ib8cb19361c42e38e3f68d7147358378fff161eb1
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/plugins/tlsopenssl/tls_openssl.c b/src/plugins/tlsopenssl/tls_openssl.c
index 903398a..f6de0e0 100644
--- a/src/plugins/tlsopenssl/tls_openssl.c
+++ b/src/plugins/tlsopenssl/tls_openssl.c
@@ -333,6 +333,9 @@
 	}
     }
 
+  if (svm_fifo_needs_tx_ntf (app_session->tx_fifo, wrote))
+    session_dequeue_notify (app_session);
+
   if (wrote < deq_max)
     tls_add_vpp_q_builtin_tx_evt (app_session);
 
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index 4485b74..cb83f65 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -227,6 +227,7 @@
 int app_worker_close_notify (app_worker_t * app_wrk, session_t * s);
 int app_worker_reset_notify (app_worker_t * app_wrk, session_t * s);
 int app_worker_builtin_rx (app_worker_t * app_wrk, session_t * s);
+int app_worker_builtin_tx (app_worker_t * app_wrk, session_t * s);
 segment_manager_t *app_worker_get_listen_segment_manager (app_worker_t *,
 							  session_t *);
 segment_manager_t *app_worker_get_connect_segment_manager (app_worker_t *);
diff --git a/src/vnet/session/application_worker.c b/src/vnet/session/application_worker.c
index d98c437..081dbbe 100644
--- a/src/vnet/session/application_worker.c
+++ b/src/vnet/session/application_worker.c
@@ -344,6 +344,18 @@
 }
 
 int
+app_worker_builtin_tx (app_worker_t * app_wrk, session_t * s)
+{
+  application_t *app = application_get (app_wrk->app_index);
+
+  if (!app->cb_fns.builtin_app_tx_callback)
+    return 0;
+
+  app->cb_fns.builtin_app_tx_callback (s);
+  return 0;
+}
+
+int
 app_worker_own_session (app_worker_t * app_wrk, session_t * s)
 {
   segment_manager_t *sm;
@@ -583,7 +595,7 @@
   svm_msg_q_msg_t msg;
 
   if (app_worker_application_is_builtin (app_wrk))
-    return 0;
+    return app_worker_builtin_tx (app_wrk, s);
 
   mq = app_wrk->event_queue;
   if (lock)
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 75f7baf..1a304a6 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -452,6 +452,10 @@
 session_tx_fifo_dequeue_drop (transport_connection_t * tc, u32 max_bytes)
 {
   session_t *s = session_get (tc->s_index, tc->thread_index);
+
+  if (svm_fifo_needs_tx_ntf (s->tx_fifo, max_bytes))
+    session_dequeue_notify (s);
+
   return svm_fifo_dequeue_drop (s->tx_fifo, max_bytes);
 }
 
diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c
index 1a04658..067ab58 100644
--- a/src/vnet/session/session_node.c
+++ b/src/vnet/session/session_node.c
@@ -792,6 +792,9 @@
       else if (svm_fifo_max_dequeue_cons (ctx->s->tx_fifo) > 0)
 	if (svm_fifo_set_event (ctx->s->tx_fifo))
 	  vec_add1 (wrk->pending_event_vector, *e);
+
+      if (svm_fifo_needs_tx_ntf (ctx->s->tx_fifo, ctx->max_len_to_snd))
+	session_dequeue_notify (ctx->s);
     }
   return SESSION_TX_OK;
 }
@@ -905,9 +908,8 @@
 
   for (i = 0; i < n_events; i++)
     {
-      session_t *s;		/* $$$ prefetch 1 ahead maybe */
       session_event_t *e;
-      u8 need_tx_ntf;
+      session_t *s;
 
       e = &fifo_events[i];
       switch (e->event_type)
@@ -933,14 +935,7 @@
 	   * different nodes */
 	  rv = (smm->session_tx_fns[s->session_type]) (vm, node, wrk, e,
 						       &n_tx_packets);
-	  if (PREDICT_TRUE (rv == SESSION_TX_OK))
-	    {
-	      need_tx_ntf = svm_fifo_needs_tx_ntf (s->tx_fifo,
-						   wrk->ctx.max_len_to_snd);
-	      if (PREDICT_FALSE (need_tx_ntf))
-		session_dequeue_notify (s);
-	    }
-	  else if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
+	  if (PREDICT_FALSE (rv == SESSION_TX_NO_BUFFERS))
 	    {
 	      vlib_node_increment_counter (vm, node->node_index,
 					   SESSION_QUEUE_ERROR_NO_BUFFER, 1);