aboutsummaryrefslogtreecommitdiffstats
path: root/src/vcl/vcl_private.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-10-14 16:35:58 -0700
committerFlorin Coras <florin.coras@gmail.com>2020-10-15 16:59:55 +0000
commitc127d5ad0a9c09b25facabf28288324f125701ad (patch)
tree25d310d446781014c11c44a4055f6d369e227b49 /src/vcl/vcl_private.c
parente8346c8fd49d611d4093f62e414c15470254d436 (diff)
vcl: refactor session state enum
Only allow one state instead of using flags. Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I08ffccbf8c3f6e2f61533996bb36c799cbc931e7
Diffstat (limited to 'src/vcl/vcl_private.c')
-rw-r--r--src/vcl/vcl_private.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/vcl/vcl_private.c b/src/vcl/vcl_private.c
index fd35db0b678..a1c252d9e99 100644
--- a/src/vcl/vcl_private.c
+++ b/src/vcl/vcl_private.c
@@ -226,46 +226,48 @@ vcl_worker_ctrl_mq (vcl_worker_t * wrk)
}
int
-vcl_session_read_ready (vcl_session_t * session)
+vcl_session_read_ready (vcl_session_t * s)
{
u32 max_deq;
/* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
+ if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "ERROR: session %u: cannot read from an epoll session!",
- session->session_index);
+ s->session_index);
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN))))
+ if (PREDICT_FALSE (!(vcl_session_is_ready (s)
+ || s->session_state == VCL_STATE_LISTEN)))
{
- vcl_session_state_t state = session->session_state;
+ vcl_session_state_t state = s->session_state;
int rv;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ rv = (state == VCL_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,
+ s->session_index, s->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);
+ if (s->session_state == VCL_STATE_LISTEN)
+ return clib_fifo_elts (s->accept_evts_fifo);
- if (vcl_session_is_ct (session))
- return svm_fifo_max_dequeue_cons (session->ct_rx_fifo);
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_dequeue_cons (s->ct_rx_fifo);
- max_deq = svm_fifo_max_dequeue_cons (session->rx_fifo);
+ max_deq = svm_fifo_max_dequeue_cons (s->rx_fifo);
- if (session->is_dgram)
+ if (s->is_dgram)
{
session_dgram_pre_hdr_t ph;
if (max_deq <= SESSION_CONN_HDR_LEN)
return 0;
- if (svm_fifo_peek (session->rx_fifo, 0, sizeof (ph), (u8 *) & ph) < 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;
@@ -277,49 +279,50 @@ vcl_session_read_ready (vcl_session_t * session)
}
int
-vcl_session_write_ready (vcl_session_t * session)
+vcl_session_write_ready (vcl_session_t * s)
{
/* Assumes caller has acquired spinlock: vcm->sessions_lockp */
- if (PREDICT_FALSE (session->is_vep))
+ if (PREDICT_FALSE (s->is_vep))
{
VDBG (0, "session %u [0x%llx]: cannot write to an epoll session!",
- session->session_index, session->vpp_handle);
+ s->session_index, s->vpp_handle);
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (session->session_state & STATE_LISTEN))
+ if (PREDICT_FALSE (s->session_state == VCL_STATE_LISTEN))
{
- if (session->tx_fifo)
- return svm_fifo_max_enqueue_prod (session->tx_fifo);
+ if (s->tx_fifo)
+ return svm_fifo_max_enqueue_prod (s->tx_fifo);
else
return VPPCOM_EBADFD;
}
- if (PREDICT_FALSE (!(session->session_state & STATE_OPEN)))
+ if (PREDICT_FALSE (!vcl_session_is_ready (s)))
{
- vcl_session_state_t state = session->session_state;
+ vcl_session_state_t state = s->session_state;
int rv;
- rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN);
+ rv = (state == VCL_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,
+ s->session_index, s->vpp_handle, state,
vppcom_session_state_str (state), rv, vppcom_retval_str (rv));
return rv;
}
- if (vcl_session_is_ct (session))
- return svm_fifo_max_enqueue_prod (session->ct_tx_fifo);
+ if (vcl_session_is_ct (s))
+ return svm_fifo_max_enqueue_prod (s->ct_tx_fifo);
- if (session->is_dgram)
+ if (s->is_dgram)
{
- u32 max_enq = svm_fifo_max_enqueue_prod (session->tx_fifo);
+ 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 (session->tx_fifo);
+ return svm_fifo_max_enqueue_prod (s->tx_fifo);
}
int