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.c106
1 files changed, 45 insertions, 61 deletions
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index a1c252d9e99..54187a7ad02 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -228,9 +228,6 @@ vcl_worker_ctrl_mq (vcl_worker_t * wrk)
int
vcl_session_read_ready (vcl_session_t * s)
{
- u32 max_deq;
-
- /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "ERROR: session %u: cannot read from an epoll session!",
@@ -238,50 +235,43 @@ vcl_session_read_ready (vcl_session_t * s)
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(vcl_session_is_ready (s)
- || s->session_state == VCL_STATE_LISTEN)))
+ if (vcl_session_is_open (s))
{
- vcl_session_state_t state = s->session_state;
- int rv;
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_dequeue_cons (s->ct_rx_fifo);
- rv = (state == VCL_STATE_DISCONNECT) ?
- VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
+ if (s->is_dgram)
+ {
+ session_dgram_pre_hdr_t ph;
+ u32 max_deq;
+
+ max_deq = svm_fifo_max_dequeue_cons (s->rx_fifo);
+ if (max_deq <= SESSION_CONN_HDR_LEN)
+ return 0;
+ if (svm_fifo_peek (s->rx_fifo, 0, sizeof (ph), (u8 *) & ph) < 0)
+ return 0;
+ if (ph.data_length + SESSION_CONN_HDR_LEN > max_deq)
+ return 0;
+
+ return ph.data_length;
+ }
- VDBG (1, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
- s->session_index, s->vpp_handle, state,
- vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
- return rv;
+ return svm_fifo_max_dequeue_cons (s->rx_fifo);
}
-
- if (s->session_state == VCL_STATE_LISTEN)
- return clib_fifo_elts (s->accept_evts_fifo);
-
- if (vcl_session_is_ct (s))
- return svm_fifo_max_dequeue_cons (s->ct_rx_fifo);
-
- max_deq = svm_fifo_max_dequeue_cons (s->rx_fifo);
-
- if (s->is_dgram)
+ else if (s->session_state == VCL_STATE_LISTEN)
{
- session_dgram_pre_hdr_t ph;
-
- if (max_deq <= SESSION_CONN_HDR_LEN)
- return 0;
- if (svm_fifo_peek (s->rx_fifo, 0, sizeof (ph), (u8 *) & ph) < 0)
- return 0;
- if (ph.data_length + SESSION_CONN_HDR_LEN > max_deq)
- return 0;
-
- return ph.data_length;
+ return clib_fifo_elts (s->accept_evts_fifo);
+ }
+ else
+ {
+ return (s->session_state == VCL_STATE_DISCONNECT) ?
+ VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
}
-
- return max_deq;
}
int
vcl_session_write_ready (vcl_session_t * s)
{
- /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
@@ -289,40 +279,34 @@ vcl_session_write_ready (vcl_session_t * s)
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (s->session_state == VCL_STATE_LISTEN))
+ if (vcl_session_is_open (s))
+ {
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_enqueue_prod (s->ct_tx_fifo);
+
+ if (s->is_dgram)
+ {
+ u32 max_enq = svm_fifo_max_enqueue_prod (s->tx_fifo);
+
+ if (max_enq <= sizeof (session_dgram_hdr_t))
+ return 0;
+ return max_enq - sizeof (session_dgram_hdr_t);
+ }
+
+ return svm_fifo_max_enqueue_prod (s->tx_fifo);
+ }
+ else if (s->session_state == VCL_STATE_LISTEN)
{
if (s->tx_fifo)
return svm_fifo_max_enqueue_prod (s->tx_fifo);
else
return VPPCOM_EBADFD;
}
-
- if (PREDICT_FALSE (!vcl_session_is_ready (s)))
+ else
{
- vcl_session_state_t state = s->session_state;
- int rv;
-
- rv = (state == VCL_STATE_DISCONNECT) ?
+ return (s->session_state == VCL_STATE_DISCONNECT) ?
VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
- VDBG (0, "session %u [0x%llx]: not open! state 0x%x (%s), ret %d (%s)",
- s->session_index, s->vpp_handle, state,
- vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
- return rv;
}
-
- if (vcl_session_is_ct (s))
- return svm_fifo_max_enqueue_prod (s->ct_tx_fifo);
-
- if (s->is_dgram)
- {
- u32 max_enq = svm_fifo_max_enqueue_prod (s->tx_fifo);
-
- if (max_enq <= sizeof (session_dgram_hdr_t))
- return 0;
- return max_enq - sizeof (session_dgram_hdr_t);
- }
-
- return svm_fifo_max_enqueue_prod (s->tx_fifo);
}
int