+ svm_fifo_dequeue_drop (f, wrote);
+
+ return wrote;
+}
+
+static int
+openssl_write_from_fifo_into_ssl (svm_fifo_t * f, SSL * ssl, u32 len)
+{
+ svm_fifo_chunk_t *c;
+ int wrote = 0, rv;
+ u32 deq_now;
+
+ svm_fifo_fill_chunk_list (f);
+
+ deq_now = clib_min (svm_fifo_max_read_chunk (f), len);
+ wrote = SSL_write (ssl, svm_fifo_head (f), deq_now);
+ if (wrote <= 0)
+ return 0;
+
+ if (wrote == deq_now)
+ {
+ c = svm_fifo_head_chunk (f);
+ while (wrote < len)
+ {
+ c = c->next;
+ deq_now = clib_min (c->length, len - wrote);
+ rv = SSL_write (ssl, c->data, deq_now);
+ wrote += rv > 0 ? rv : 0;
+
+ if (rv < deq_now)
+ break;
+ }
+ }
+
+ svm_fifo_dequeue_drop (f, wrote);
+
+ return wrote;
+}
+
+static int
+openssl_try_handshake_read (openssl_ctx_t * oc, session_t * tls_session)
+{
+ svm_fifo_t *f;
+ u32 deq_max;
+
+ f = tls_session->rx_fifo;
+ deq_max = svm_fifo_max_dequeue_cons (f);
+ if (!deq_max)
+ return 0;
+
+ return openssl_write_from_fifo_into_bio (f, oc->wbio, deq_max);
+}
+
+static int
+openssl_try_handshake_write (openssl_ctx_t * oc, session_t * tls_session)
+{
+ u32 read;
+
+ if (BIO_ctrl_pending (oc->rbio) <= 0)
+ return 0;
+
+ read = openssl_read_from_bio_into_fifo (tls_session->tx_fifo, oc->rbio);
+ if (read)
+ tls_add_vpp_q_tx_evt (tls_session);
+