summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/hs_apps/vcl/sock_test_server.c2
-rw-r--r--src/vcl/vcl_private.c106
-rw-r--r--src/vcl/vcl_private.h3
-rw-r--r--src/vcl/vppcom.c4
4 files changed, 50 insertions, 65 deletions
diff --git a/src/plugins/hs_apps/vcl/sock_test_server.c b/src/plugins/hs_apps/vcl/sock_test_server.c
index 843d80e7249..6e4d6ea17fd 100644
--- a/src/plugins/hs_apps/vcl/sock_test_server.c
+++ b/src/plugins/hs_apps/vcl/sock_test_server.c
@@ -284,6 +284,8 @@ new_client (void)
stfail ("new_client accept()");
stinf ("Got a connection -- fd = %d (0x%08x)!\n", client_fd, client_fd);
+ if (fcntl (client_fd, F_SETFL, O_NONBLOCK) < 0)
+ stfail ("fcntl()");
conn->fd = client_fd;
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
diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h
index 8e4c229ea76..03dbbf51cc4 100644
--- a/src/vcl/vcl_private.h
+++ b/src/vcl/vcl_private.h
@@ -564,8 +564,7 @@ static inline u8
vcl_session_is_open (vcl_session_t * s)
{
return ((vcl_session_is_ready (s))
- || (s->session_state == VCL_STATE_LISTEN
- && s->session_type == VPPCOM_PROTO_UDP));
+ || (s->session_state == VCL_STATE_LISTEN && vcl_session_is_cl (s)));
}
static inline u8
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c
index bb59358b357..99e3feacdfb 100644
--- a/src/vcl/vppcom.c
+++ b/src/vcl/vppcom.c
@@ -923,7 +923,7 @@ vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e)
case SESSION_IO_EVT_RX:
case SESSION_IO_EVT_TX:
s = vcl_session_get (wrk, e->session_index);
- if (!s || !(vcl_session_is_ready (s)))
+ if (!s || !vcl_session_is_open (s))
break;
vec_add1 (wrk->unhandled_evts_vector, *e);
break;
@@ -1356,7 +1356,7 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * s,
vppcom_retval_str (rv));
return rv;
}
- else if ((vcl_session_is_ready (s))
+ else if (vcl_session_is_ready (s)
|| (vcl_session_is_connectable_listener (wrk, s)))
{
rv = vppcom_session_disconnect (sh);