Break up vpe.api
[vpp.git] / src / vcl / vcom.c
index be1e4c5..ed52bfa 100644 (file)
@@ -2568,7 +2568,6 @@ accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
   return libc_accept (__fd, __addr, __addr_len);
 }
 
-#ifdef __USE_GNU
 /*
  * Similar to 'accept' but takes an additional parameter to specify
  * flags.
@@ -2592,9 +2591,14 @@ int
 accept4 (int __fd, __SOCKADDR_ARG __addr,
         socklen_t * __restrict __addr_len, int __flags)
 {
-  int rv;
+  int rv = 0;
   pid_t pid = getpid ();
 
+  fprintf (stderr,
+          "[%d] accept4: in the beginning... "
+          "'%04d'='%04d', '%p', '%p', '%04x'\n",
+          pid, rv, __fd, __addr, __addr_len, __flags);
+
   if (is_vcom_socket_fd (__fd))
     {
       if (VCOM_DEBUG > 0)
@@ -2602,7 +2606,7 @@ accept4 (int __fd, __SOCKADDR_ARG __addr,
       rv = vcom_accept4 (__fd, __addr, __addr_len, __flags);
       if (VCOM_DEBUG > 0)
        fprintf (stderr,
-                "[%d] accept4: "
+                "[%d] accept4: VCL "
                 "'%04d'='%04d', '%p', '%p', '%04x'\n",
                 pid, rv, __fd, __addr, __addr_len, __flags);
       if (VCOM_DEBUG > 0)
@@ -2614,11 +2618,14 @@ accept4 (int __fd, __SOCKADDR_ARG __addr,
        }
       return rv;
     }
+  fprintf (stderr,
+          "[%d] accept4: libc "
+          "'%04d'='%04d', '%p', '%p', '%04x'\n",
+          pid, rv, __fd, __addr, __addr_len, __flags);
+
   return libc_accept4 (__fd, __addr, __addr_len, __flags);
 }
 
-#endif
-
 /*
  * Shut down all or part of the connection open on socket FD.
  * HOW determines what to shut down:
@@ -2792,54 +2799,19 @@ epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event)
   int rv;
   pid_t pid = getpid ();
 
-  if (is_vcom_epfd (__epfd))
-    {
-      /* TBD: currently limiting epoll to support only vcom fds */
-      if (is_vcom_socket_fd (__fd))
-       {
-         rv = vcom_epoll_ctl (__epfd, __op, __fd, __event);
-         if (VCOM_DEBUG > 0)
-           fprintf (stderr,
-                    "[%d] epoll_ctl: "
-                    "'%04d'='%04d', '%04d', '%04d'\n",
-                    pid, rv, __epfd, __op, __fd);
-         if (rv != 0)
-           {
-             errno = -rv;
-             return -1;
-           }
-         return 0;
-       }
-      else
-       {
-         /*
-          * TBD: currently epoll does not support kernel fds
-          * or epoll fds */
-         errno = EBADF;
-         return -1;
-       }
-    }
-  else
+  rv = vcom_epoll_ctl (__epfd, __op, __fd, __event);
+  if (VCOM_DEBUG > 0)
+    fprintf (stderr,
+            "[%d] epoll_ctl: "
+            "'%04d'='%04d', '%04d', '%04d'\n", pid, rv, __epfd, __op, __fd);
+  if (rv != 0)
     {
-      /* epfd is not an epoll file descriptor */
-      errno = EINVAL;
+      errno = -rv;
       return -1;
     }
   return 0;
 }
 
-int
-vcom_epoll_wait (int __epfd, struct epoll_event *__events,
-                int __maxevents, int __timeout)
-{
-  if (vcom_init () != 0)
-    {
-      return -1;
-    }
-
-  return vcom_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL);
-}
-
 int
 epoll_wait (int __epfd, struct epoll_event *__events,
            int __maxevents, int __timeout)
@@ -2849,49 +2821,29 @@ epoll_wait (int __epfd, struct epoll_event *__events,
 
   if (__maxevents <= 0 || __maxevents > EP_MAX_EVENTS)
     {
+      fprintf (stderr, "[%d] ERROR: epoll_wait() invalid maxevents %d\n",
+              pid, __maxevents);
       errno = EINVAL;
       return -1;
     }
 
-  if (is_vcom_epfd (__epfd))
-    {
-      rv = vcom_epoll_wait (__epfd, __events, __maxevents, __timeout);
-      if (VCOM_DEBUG > 0)
-       fprintf (stderr,
-                "[%d] epoll_wait: "
-                "'%04d'='%04d', '%p', "
-                "'%04d', '%04d'\n",
-                pid, rv, __epfd, __events, __maxevents, __timeout);
-      if (rv < 0)
-       {
-         errno = -rv;
-         return -1;
-       }
-      return rv;
-    }
-  else
+  rv =
+    vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL);
+  if (VCOM_DEBUG > 1)
+    fprintf (stderr,
+            "[%d] epoll_wait: "
+            "'%04d'='%04d', '%p', "
+            "'%04d', '%04d'\n",
+            pid, rv, __epfd, __events, __maxevents, __timeout);
+  if (rv < 0)
     {
-      errno = EINVAL;
+      errno = -rv;
       return -1;
     }
-  return 0;
+  return rv;
 }
 
 
-int
-vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
-                 int __maxevents, int __timeout, const __sigset_t * __ss)
-{
-  if (vcom_init () != 0)
-    {
-      return -1;
-    }
-
-  /* implementation */
-  return vcom_socket_epoll_pwait (__epfd, __events,
-                                 __maxevents, __timeout, __ss);
-}
-
 int
 epoll_pwait (int __epfd, struct epoll_event *__events,
             int __maxevents, int __timeout, const __sigset_t * __ss)
@@ -2907,7 +2859,9 @@ epoll_pwait (int __epfd, struct epoll_event *__events,
 
   if (is_vcom_epfd (__epfd))
     {
-      rv = vcom_epoll_pwait (__epfd, __events, __maxevents, __timeout, __ss);
+      rv =
+       vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout,
+                                __ss);
       if (VCOM_DEBUG > 0)
        fprintf (stderr,
                 "[%d] epoll_pwait: "