From 41c9e04be0ca3a081926045e78dc969dab563532 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Tue, 11 Sep 2018 00:10:41 -0700 Subject: vcl: improve read and fifo event handling Change-Id: Ic1c51818b8aa8dbd164e70bb3b7471868e5af6f6 Signed-off-by: Florin Coras --- src/vcl/CMakeLists.txt | 3 +++ src/vcl/vcl_test_server.c | 6 +++--- src/vcl/vppcom.c | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/vcl') diff --git a/src/vcl/CMakeLists.txt b/src/vcl/CMakeLists.txt index ba19ced27a6..c86f40bb0f2 100644 --- a/src/vcl/CMakeLists.txt +++ b/src/vcl/CMakeLists.txt @@ -24,6 +24,9 @@ add_vpp_library(vppcom LINK_LIBRARIES vppinfra svm vlibmemoryclient rt pthread + + DEPENDS + api_headers ) add_vpp_library(vcl_ldpreload diff --git a/src/vcl/vcl_test_server.c b/src/vcl/vcl_test_server.c index 5c8656c9603..7c1bef62d6d 100644 --- a/src/vcl/vcl_test_server.c +++ b/src/vcl/vcl_test_server.c @@ -575,8 +575,8 @@ vts_worker_loop (void *arg) } continue; } - else if ((conn->cfg.test == SOCK_TEST_TYPE_UNI) - || (conn->cfg.test == SOCK_TEST_TYPE_BI)) + if ((conn->cfg.test == SOCK_TEST_TYPE_UNI) + || (conn->cfg.test == SOCK_TEST_TYPE_BI)) { vts_server_rx (conn, rx_bytes); if (vppcom_session_attr (conn->fd, VPPCOM_ATTR_GET_NREAD, 0, @@ -584,7 +584,7 @@ vts_worker_loop (void *arg) goto read_again; continue; } - else if (isascii (conn->buf[0])) + if (isascii (conn->buf[0])) { vts_server_echo (conn, rx_bytes); } diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c index 3acd1c41e70..6d6e7d08797 100644 --- a/src/vcl/vppcom.c +++ b/src/vcl/vppcom.c @@ -1268,7 +1268,7 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, svm_msg_q_msg_t msg; session_event_t *e; svm_msg_q_t *mq; - u8 is_full; + u8 is_ct; if (PREDICT_FALSE (!buf)) return VPPCOM_EINVAL; @@ -1299,18 +1299,19 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, return rv; } - mq = vcl_session_is_ct (s) ? s->our_evt_q : wrk->app_event_queue; - svm_fifo_unset_event (rx_fifo); - is_full = svm_fifo_is_full (rx_fifo); + is_ct = vcl_session_is_ct (s); + mq = is_ct ? s->our_evt_q : wrk->app_event_queue; if (svm_fifo_is_empty (rx_fifo)) { if (is_nonblocking) { + svm_fifo_unset_event (rx_fifo); return VPPCOM_OK; } - while (1) + while (svm_fifo_is_empty (rx_fifo)) { + svm_fifo_unset_event (rx_fifo); svm_msg_q_lock (mq); if (svm_msg_q_is_empty (mq)) svm_msg_q_wait (mq); @@ -1318,20 +1319,16 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, svm_msg_q_sub_w_lock (mq, &msg); e = svm_msg_q_msg_data (mq, &msg); svm_msg_q_unlock (mq); - if (!vcl_is_rx_evt_for_session (e, s->session_index, - s->our_evt_q != 0)) + if (!vcl_is_rx_evt_for_session (e, s->session_index, is_ct)) { vcl_handle_mq_ctrl_event (wrk, e); svm_msg_q_free_msg (mq, &msg); continue; } - svm_fifo_unset_event (rx_fifo); svm_msg_q_free_msg (mq, &msg); + if (PREDICT_FALSE (s->session_state == STATE_CLOSE_ON_EMPTY)) return 0; - if (svm_fifo_is_empty (rx_fifo)) - continue; - break; } } @@ -1340,7 +1337,10 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, else n_read = app_recv_stream_raw (rx_fifo, buf, n, 0, peek); - if (vcl_session_is_ct (s) && is_full) + if (svm_fifo_is_empty (rx_fifo)) + svm_fifo_unset_event (rx_fifo); + + if (is_ct && n_read + svm_fifo_max_dequeue (rx_fifo) == rx_fifo->nitems) { /* If the peer is not polling send notification */ if (!svm_fifo_has_event (s->rx_fifo)) @@ -1593,7 +1593,7 @@ if (PREDICT_FALSE (svm_fifo_is_empty (_fifo))) \ { \ svm_fifo_unset_event (_fifo); \ if (svm_fifo_is_empty (_fifo)) \ - break; \ + break; \ } \ static int -- cgit 1.2.3-korg