session: lock app worker mq for io events

Also fixes vcl client/server stats and closing procedure.

Change-Id: I7d5a274ea0a3c8ea13062bf61bf402248dfe1a19
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vcl/vcl_test_server.c b/src/vcl/vcl_test_server.c
index 2fdd7ec..5c8656c 100644
--- a/src/vcl/vcl_test_server.c
+++ b/src/vcl/vcl_test_server.c
@@ -497,6 +497,7 @@
   if (rv < 0)
     vtfail ("vppcom_epoll_ctl", rv);
 
+  ssm->active_workers += 1;
   vtinf ("Waiting for a client to connect on port %d ...", ssm->cfg.port);
 }
 
@@ -532,6 +533,12 @@
 	  if (wrk->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP))
 	    {
 	      vppcom_session_close (conn->fd);
+	      wrk->nfds -= 1;
+	      if (!wrk->nfds)
+		{
+		  vtinf ("All client connections closed\n");
+		  goto done;
+		}
 	      continue;
 	    }
 	  if (wrk->wait_events[i].data.u32 == ~0)
@@ -542,6 +549,7 @@
 
 	  if (EPOLLIN & wrk->wait_events[i].events)
 	    {
+	    read_again:
 	      rx_bytes = vcl_test_read (conn->fd, conn->buf,
 					conn->buf_size, &conn->stats);
 
@@ -563,7 +571,6 @@
 		  if (!wrk->nfds)
 		    {
 		      vtinf ("All client connections closed\n");
-		      vtinf ("May the force be with you!\n");
 		      goto done;
 		    }
 		  continue;
@@ -572,6 +579,9 @@
 		       || (conn->cfg.test == SOCK_TEST_TYPE_BI))
 		{
 		  vts_server_rx (conn, rx_bytes);
+		  if (vppcom_session_attr (conn->fd, VPPCOM_ATTR_GET_NREAD, 0,
+					   0) > 0)
+		    goto read_again;
 		  continue;
 		}
 	      else if (isascii (conn->buf[0]))