summaryrefslogtreecommitdiffstats
path: root/src/vcl/vcl_private.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcl/vcl_private.c')
-rw-r--r--src/vcl/vcl_private.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index df602b3ce87..5f9ce270508 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -391,6 +391,70 @@ vcl_cleanup_bapi (void)
vl_client_api_unmap ();
}
+int
+vcl_session_read_ready (vcl_session_t * session)
+{
+ /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+ if (PREDICT_FALSE (session->is_vep))
+ {
+ VDBG (0, "ERROR: session %u: cannot read from an epoll session!",
+ session->session_index);
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN))))
+ {
+ session_state_t state = session->session_state;
+ int rv;
+
+ rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+
+ VDBG (1, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
+ session->session_index, session->vpp_handle, state,
+ vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
+ return rv;
+ }
+
+ if (session->session_state & STATE_LISTEN)
+ return clib_fifo_elts (session->accept_evts_fifo);
+
+ return svm_fifo_max_dequeue (session->rx_fifo);
+}
+
+int
+vcl_session_write_ready (vcl_session_t * session)
+{
+ /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+ if (PREDICT_FALSE (session->is_vep))
+ {
+ VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
+ session->session_index, session->vpp_handle);
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
+ {
+ if (session->tx_fifo)
+ return svm_fifo_max_enqueue (session->tx_fifo);
+ else
+ return VPPCOM_EBADFD;
+ }
+
+ if (PREDICT_FALSE (!(session->session_state & STATE_OPEN)))
+ {
+ session_state_t state = session->session_state;
+ int rv;
+
+ rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ VDBG (0, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
+ session->session_index, session->vpp_handle, state,
+ vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
+ return rv;
+ }
+
+ return svm_fifo_max_enqueue (session->tx_fifo);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*