session tls: improve app transports tx scheduling
[vpp.git] / src / plugins / tlsopenssl / tls_openssl.c
index f25ac9f..935e014 100644 (file)
@@ -317,7 +317,7 @@ openssl_handle_handshake_failure (tls_ctx_t * ctx)
       /*
        * Also handles cleanup of the pre-allocated session
        */
-      tls_notify_app_connected (ctx, /* is failed */ 1);
+      tls_notify_app_connected (ctx, SESSION_E_TLS_HANDSHAKE);
     }
 }
 
@@ -385,11 +385,11 @@ openssl_ctx_handshake_rx (tls_ctx_t * ctx, session_t * tls_session)
           */
          if (ctx->srv_hostname)
            {
-             tls_notify_app_connected (ctx, /* is failed */ 0);
+             tls_notify_app_connected (ctx, SESSION_E_TLS_HANDSHAKE);
              return -1;
            }
        }
-      tls_notify_app_connected (ctx, /* is failed */ 0);
+      tls_notify_app_connected (ctx, SESSION_E_NONE);
     }
   else
     {
@@ -413,10 +413,10 @@ openssl_confirm_app_close (tls_ctx_t * ctx)
 }
 
 static inline int
-openssl_ctx_write (tls_ctx_t * ctx, session_t * app_session)
+openssl_ctx_write (tls_ctx_t * ctx, session_t * app_session, u32 max_write)
 {
   openssl_ctx_t *oc = (openssl_ctx_t *) ctx;
-  int wrote = 0, read, max_buf = 100 * TLS_CHUNK_SIZE, max_space;
+  int wrote = 0, read, max_buf = 4 * TLS_CHUNK_SIZE, max_space;
   u32 deq_max, to_write;
   session_t *tls_session;
   svm_fifo_t *f;
@@ -427,6 +427,8 @@ openssl_ctx_write (tls_ctx_t * ctx, session_t * app_session)
   if (!deq_max)
     goto check_tls_fifo;
 
+  deq_max = clib_min (deq_max, max_write);
+
   /* Figure out how much data to write */
   max_space = max_buf - BIO_ctrl_pending (oc->rbio);
   max_space = (max_space < 0) ? 0 : max_space;
@@ -434,17 +436,11 @@ openssl_ctx_write (tls_ctx_t * ctx, session_t * app_session)
 
   wrote = openssl_write_from_fifo_into_ssl (f, oc->ssl, to_write);
   if (!wrote)
-    {
-      tls_add_vpp_q_builtin_tx_evt (app_session);
-      goto check_tls_fifo;
-    }
+    goto check_tls_fifo;
 
   if (svm_fifo_needs_deq_ntf (f, wrote))
     session_dequeue_notify (app_session);
 
-  if (svm_fifo_max_dequeue_cons (f))
-    tls_add_vpp_q_builtin_tx_evt (app_session);
-
 check_tls_fifo:
 
   if (BIO_ctrl_pending (oc->rbio) <= 0)
@@ -455,14 +451,15 @@ check_tls_fifo:
   read = openssl_read_from_bio_into_fifo (tls_session->tx_fifo, oc->rbio);
   if (!read)
     {
-      tls_add_vpp_q_builtin_tx_evt (app_session);
+      /* Request tx reschedule of the app session */
+      app_session->flags |= SESSION_F_CUSTOM_TX;
       return wrote;
     }
 
   tls_add_vpp_q_tx_evt (tls_session);
 
   if (BIO_ctrl_pending (oc->rbio) > 0)
-    tls_add_vpp_q_builtin_tx_evt (app_session);
+    app_session->flags |= SESSION_F_CUSTOM_TX;
   else if (ctx->app_closed)
     openssl_confirm_app_close (ctx);
 
@@ -472,7 +469,7 @@ check_tls_fifo:
 static inline int
 openssl_ctx_read (tls_ctx_t * ctx, session_t * tls_session)
 {
-  int read, wrote = 0, max_space, max_buf = 100 * TLS_CHUNK_SIZE;
+  int read, wrote = 0, max_space, max_buf = 4 * TLS_CHUNK_SIZE;
   openssl_ctx_t *oc = (openssl_ctx_t *) ctx;
   u32 deq_max, to_write;
   session_t *app_session;