VCL: improve debug output

- Refactor debug output to include vpp handle associated
  with session id where appropriate.
- Fix vcom_connect return value on error.
- Refactor vcom_socket_epoll_pwait().
- Fix sock_test_server/client connect failure handling.

Change-Id: I2649596aa4b8a77d9bd876409a76810cb2785797
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
diff --git a/src/vcl/vcom_socket.c b/src/vcl/vcom_socket.c
index e87fd8a..81a4b76 100644
--- a/src/vcl/vcom_socket.c
+++ b/src/vcl/vcom_socket.c
@@ -3011,12 +3011,10 @@
 {
   vcom_socket_main_t *vsm = &vcom_socket_main;
   int rv = -EBADF;
-  int rv2;
   double time_to_wait = (double) 0;
   double timeout, now = 0;
   vcom_epoll_t *vepoll;
   i32 vep_idx;
-  static struct epoll_event *libc_ev = 0;
 
   /* validate __event */
   if (!__events || (__timeout < -1))
@@ -3070,42 +3068,40 @@
 		 "__timeout = %d)\n",
 		 getpid (), vepoll->vcl_cnt, vepoll->libc_cnt,
 		 time_to_wait, __timeout);
-      vec_validate (libc_ev, __maxevents);
       timeout = clib_time_now (&vsm->clib_time) + time_to_wait;
       do
 	{
 	  rv = vppcom_epoll_wait (vep_idx, __events, __maxevents, 0);
-	  rv2 = libc_epoll_pwait (__epfd, libc_ev, __maxevents, 1, __ss);
-	  if (VCOM_DEBUG == 666)
-	    fprintf (stderr, "[%d] vcom_socket_epoll_pwait: "
-		     "rv = %d, rv2 = %d, timeout = %f, now = %f\n",
-		     getpid (), rv, rv2, timeout, now);
-	  if ((rv > 0) || (rv2 > 0))
+	  if (rv > 0)
 	    {
 	      if (VCOM_DEBUG > 2)
 		fprintf (stderr, "[%d] vcom_socket_epoll_pwait: "
-			 "rv = %d, rv2 = %d\n", getpid (), rv, rv2);
-	      int n = __maxevents - rv;
-	      n = rv2 <= n ? rv2 : n;
-	      rv = (rv > 0) ? rv : 0;
-
-	      clib_memcpy (&__events[rv], libc_ev, n * sizeof (*libc_ev));
-	      rv += rv2;
+			 "vppcom_epoll_wait() returned %d\n", getpid (), rv);
 	      goto out;
 	    }
-	  else if ((rv < 0) || (rv2 < 0))
+	  else if (rv < 0)
 	    {
-	      if (rv < 0)
-		fprintf (stderr,
-			 "[%d] ERROR: vppcom_epoll_wait() returned %d\n",
-			 getpid (), rv);
-	      if (rv2 < 0)
-		{
-		  fprintf (stderr,
-			   "[%d] ERROR: libc_epoll_wait() failed, errno %d\n",
-			   getpid (), errno);
-		  rv = (rv < 0) ? rv : -errno;
-		}
+	      if (VCOM_DEBUG > 2)
+		fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: "
+			 "vppcom_epoll_wait() returned %d\n", getpid (), rv);
+
+	      goto out;
+	    }
+	  rv = libc_epoll_pwait (__epfd, __events, __maxevents, 1, __ss);
+	  if (rv > 0)
+	    {
+	      if (VCOM_DEBUG > 2)
+		fprintf (stderr, "[%d] vcom_socket_epoll_pwait: "
+			 "libc_epoll_pwait() returned %d\n", getpid (), rv);
+	      goto out;
+	    }
+	  else if (rv < 0)
+	    {
+	      int errno_val = errno;
+	      perror ("libc_epoll_wait");
+	      fprintf (stderr, "[%d]  vcom_socket_epoll_pwait: "
+		       "libc_epoll_wait() failed, errno %d\n",
+		       getpid (), errno_val);
 	      goto out;
 	    }
 	  if (__timeout != -1)
@@ -3113,9 +3109,7 @@
 	}
       while (now < timeout);
     }
-
 out:
-  vec_reset_length (libc_ev);
   return rv;
 }