vcl: add api to retrieve num bytes for tx
[vpp.git] / src / vcl / vppcom.c
index 4b2f1f1..a0bbae1 100644 (file)
@@ -545,6 +545,7 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp)
        {
          session->session_state = VCL_STATE_DETACHED;
          session->vpp_handle = mp->handle;
+         session->vpp_error = mp->retval;
          return sid;
        }
       else
@@ -1161,7 +1162,10 @@ vppcom_wait_for_session_state_change (u32 session_index,
        }
       if (session->session_state == VCL_STATE_DETACHED)
        {
-         return VPPCOM_ECONNREFUSED;
+         if (session->vpp_error == SESSION_E_ALREADY_LISTENING)
+           return VPPCOM_EADDRINUSE;
+         else
+           return VPPCOM_ECONNREFUSED;
        }
 
       if (svm_msg_q_sub (wrk->app_event_queue, &msg, SVM_Q_NOWAIT, 0))
@@ -1436,12 +1440,10 @@ vppcom_app_destroy (void)
 
   current_wrk = vcl_worker_get_current ();
 
-  /* *INDENT-OFF* */
   pool_foreach (wrk, vcm->workers)  {
     if (current_wrk != wrk)
       vcl_worker_cleanup (wrk, 0 /* notify vpp */ );
   }
-  /* *INDENT-ON* */
 
   vcl_api_detach (current_wrk);
   vcl_worker_cleanup (current_wrk, 0 /* notify vpp */ );
@@ -1678,7 +1680,7 @@ vppcom_session_bind (uint32_t session_handle, vppcom_endpt_t * ep)
   vcl_evt (VCL_EVT_BIND, session);
 
   if (session->session_type == VPPCOM_PROTO_UDP)
-    vppcom_session_listen (session_handle, 10);
+    return vppcom_session_listen (session_handle, 10);
 
   return VPPCOM_OK;
 }
@@ -2052,13 +2054,13 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n,
 
   if (svm_fifo_is_empty_cons (rx_fifo))
     {
+      if (is_ct)
+       svm_fifo_unset_event (s->rx_fifo);
+      svm_fifo_unset_event (rx_fifo);
       if (is_nonblocking)
        {
          if (vcl_session_is_closing (s))
            return vcl_session_closing_error (s);
-         if (is_ct)
-           svm_fifo_unset_event (s->rx_fifo);
-         svm_fifo_unset_event (rx_fifo);
          return VPPCOM_EWOULDBLOCK;
        }
       while (svm_fifo_is_empty_cons (rx_fifo))
@@ -2164,11 +2166,13 @@ vppcom_session_read_segments (uint32_t session_handle,
 
   if (svm_fifo_is_empty_cons (rx_fifo))
     {
+      if (is_ct)
+       svm_fifo_unset_event (s->rx_fifo);
+      svm_fifo_unset_event (rx_fifo);
       if (is_nonblocking)
        {
-         if (is_ct)
-           svm_fifo_unset_event (s->rx_fifo);
-         svm_fifo_unset_event (rx_fifo);
+         if (vcl_session_is_closing (s))
+           return vcl_session_closing_error (s);
          return VPPCOM_EWOULDBLOCK;
        }
       while (svm_fifo_is_empty_cons (rx_fifo))
@@ -2824,7 +2828,7 @@ vppcom_epoll_create (void)
 
 static void
 vcl_epoll_ctl_add_unhandled_event (vcl_worker_t *wrk, vcl_session_t *s,
-                                  u8 is_epollet, session_evt_type_t evt)
+                                  u32 is_epollet, session_evt_type_t evt)
 {
   if (!is_epollet)
     {
@@ -3581,7 +3585,19 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
       VDBG (2, "VPPCOM_ATTR_GET_NWRITE: sh %u, nwrite = %d", session_handle,
            rv);
       break;
-
+    case VPPCOM_ATTR_GET_NWRITEQ:
+      if (PREDICT_FALSE (!buffer || !buflen || *buflen != sizeof (int)))
+       {
+         rv = VPPCOM_EINVAL;
+         break;
+       }
+      if (!session->tx_fifo || session->session_state == VCL_STATE_DETACHED)
+       {
+         rv = VPPCOM_EINVAL;
+         break;
+       }
+      *(int *) buffer = svm_fifo_max_dequeue (session->tx_fifo);
+      break;
     case VPPCOM_ATTR_GET_FLAGS:
       if (PREDICT_TRUE (buffer && buflen && (*buflen >= sizeof (*flags))))
        {