vcl: cleanup read and write ready
Type: improvement
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ib6afedf24c7bd7cc0d98bb324a83517030a05aa7
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index a1c252d..54187a7 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -228,9 +228,6 @@
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 @@
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) ?
+ 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;
+ }
+
+ return svm_fifo_max_dequeue_cons (s->rx_fifo);
+ }
+ else if (s->session_state == VCL_STATE_LISTEN)
+ {
+ return clib_fifo_elts (s->accept_evts_fifo);
+ }
+ else
+ {
+ return (s->session_state == VCL_STATE_DISCONNECT) ?
VPPCOM_ECONNRESET : VPPCOM_ENOTCONN;
-
- 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;
}
-
- 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)
- {
- 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 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 @@
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