aboutsummaryrefslogtreecommitdiffstats
path: root/vcl-ldpreload
diff options
context:
space:
mode:
authorshrinivasan ganapathy <shrinivasanganapathy@gmail.com>2017-10-04 02:48:31 -0700
committershrinivasan ganapathy <shrinivasanganapathy@gmail.com>2017-10-04 02:48:31 -0700
commit34956cc3d34d6e7b9c7ed5a27d9eebd6fe404280 (patch)
tree8828dcf092313a22b664c9de02c1201709548f48 /vcl-ldpreload
parent4cf3180c5a7cdd4e6a733ea2712ff2788c2e83ad (diff)
VCL_LDPRELOAD epoll implementation
-epoll_create implementation Change-Id: If05b5f44e48455f5a6f7a8096c1d020e7f3cd9cc Signed-off-by: shrinivasan ganapathy <shrinivasanganapathy@gmail.com>
Diffstat (limited to 'vcl-ldpreload')
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom.c1381
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom.h56
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h85
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c1262
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h259
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.c287
-rw-r--r--vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.h49
7 files changed, 2143 insertions, 1236 deletions
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom.c b/vcl-ldpreload/src/libvcl-ldpreload/vcom.c
index 37cf936..f997d4d 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom.c
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom.c
@@ -78,7 +78,7 @@ int
vcom_set_app_name (char *__app_name)
{
return snprintf (vcom_app_name, MAX_VCOM_APP_NAME, "vcom-%s-%d",
- __app_name, getpid ()) < 0 ? -1 : 0;
+ __app_name, getpid ()) < 0 ? -1 : 0;
}
static char *
@@ -112,21 +112,21 @@ vcom_init ()
if (!is_vcom_init)
{
if (vppcom_app_create (vcom_get_app_name ()) != 0)
- {
- printf ("\n[%d] vcom_init...failed!\n", pid);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] vcom_init: vppcom_app_create failed!\n", pid);
- return -1;
- }
+ {
+ printf ("\n[%d] vcom_init...failed!\n", pid);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] vcom_init: vppcom_app_create failed!\n", pid);
+ return -1;
+ }
if (vcom_socket_main_init () != 0)
- {
- printf ("\n[%d] vcom_init...failed!\n", pid);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] vcom_init: vcom_socket_main_init failed!\n", pid);
- return -1;
- }
+ {
+ printf ("\n[%d] vcom_init...failed!\n", pid);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] vcom_init: vcom_socket_main_init failed!\n", pid);
+ return -1;
+ }
is_vcom_init = 1;
printf ("\n[%d] vcom_init...done!\n", pid);
@@ -154,6 +154,13 @@ is_vcom_socket_fd (int fd)
return vcom_socket_is_vcom_fd (fd);
}
+static inline int
+is_vcom_epfd (int epfd)
+{
+ return vcom_socket_is_vcom_epfd (epfd);
+}
+
+
/*
*
* Generic glibc fd api
@@ -193,20 +200,20 @@ close (int __fd)
int rv;
pid_t pid = getpid ();
- if (is_vcom_socket_fd (__fd))
+ if (is_vcom_socket_fd (__fd) || is_vcom_epfd (__fd))
{
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
rv = vcom_close (__fd);
if (VCOM_DEBUG > 0)
- fprintf (stderr, "[%d] close: " "'%04d'='%04d'\n", pid, rv, __fd);
+ fprintf (stderr, "[%d] close: " "'%04d'='%04d'\n", pid, rv, __fd);
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_close (__fd);
@@ -238,23 +245,23 @@ read (int __fd, void *__buf, size_t __nbytes)
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] read:1 "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- (int) size, __fd, __buf, (int) __nbytes);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] read:1 "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ (int) size, __fd, __buf, (int) __nbytes);
size = vcom_read (__fd, __buf, __nbytes);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] read:2 "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- (int) size, __fd, __buf, (int) __nbytes);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] read:2 "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ (int) size, __fd, __buf, (int) __nbytes);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_read (__fd, __buf, __nbytes);
@@ -285,23 +292,23 @@ write (int __fd, const void *__buf, size_t __n)
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] write:1 "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- (int) size, __fd, __buf, (int) __n);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] write:1 "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ (int) size, __fd, __buf, (int) __n);
size = vcom_write (__fd, __buf, __n);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] write:2 "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- (int) size, __fd, __buf, (int) __n);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] write:2 "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ (int) size, __fd, __buf, (int) __n);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_write (__fd, __buf, __n);
@@ -350,14 +357,14 @@ fcntl (int __fd, int __cmd, ...)
{
rv = vcom_fcntl_va (__fd, __cmd, ap);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] fcntl: "
- "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __cmd);
+ fprintf (stderr,
+ "[%d] fcntl: "
+ "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __cmd);
if (rv < 0)
- {
- errno = -rv;
- rv = -1;
- }
+ {
+ errno = -rv;
+ rv = -1;
+ }
goto out;
}
rv = libc_vfcntl (__fd, __cmd, ap);
@@ -392,10 +399,10 @@ out:
*/
static inline int
vcom_fd_clear (int __nfds,
- int *__new_nfds,
- fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds)
+ int *__new_nfds,
+ fd_set * __restrict __readfds,
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds)
{
int fd;
/* invalid max_fd is -1 */
@@ -464,14 +471,14 @@ vcom_fd_clear (int __nfds,
*/
static inline int
vcom_fd_set (int __nfds,
- /* dest */
- int *__new_nfds,
- fd_set * __restrict __readfds,
- fd_set * __restrict __writefds, fd_set * __restrict __exceptfds,
- /* src */
- fd_set * __restrict __saved_readfds,
- fd_set * __restrict __saved_writefds,
- fd_set * __restrict __saved_exceptfds)
+ /* dest */
+ int *__new_nfds,
+ fd_set * __restrict __readfds,
+ fd_set * __restrict __writefds, fd_set * __restrict __exceptfds,
+ /* src */
+ fd_set * __restrict __saved_readfds,
+ fd_set * __restrict __saved_writefds,
+ fd_set * __restrict __saved_exceptfds)
{
int fd;
/* invalid max_fd is -1 */
@@ -536,21 +543,21 @@ vcom_fd_set (int __nfds,
*/
static inline void
vcom_fd_set_split (
- /* src, select sets */
- int nfds,
- fd_set * __restrict readfds,
- fd_set * __restrict writefds,
- fd_set * __restrict exceptfds,
- /* dest1, vcom sets */
- int *vcom_nfds,
- fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds, int *vcom_nfd,
- /* dest2, libc sets */
- int *libc_nfds,
- fd_set * __restrict libc_readfds,
- fd_set * __restrict libc_writefds,
- fd_set * __restrict libc_exceptfds, int *libc_nfd)
+ /* src, select sets */
+ int nfds,
+ fd_set * __restrict readfds,
+ fd_set * __restrict writefds,
+ fd_set * __restrict exceptfds,
+ /* dest1, vcom sets */
+ int *vcom_nfds,
+ fd_set * __restrict vcom_readfds,
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds, int *vcom_nfd,
+ /* dest2, libc sets */
+ int *libc_nfds,
+ fd_set * __restrict libc_readfds,
+ fd_set * __restrict libc_writefds,
+ fd_set * __restrict libc_exceptfds, int *libc_nfd)
{
int fd;
@@ -624,21 +631,21 @@ vcom_fd_set_split (
*/
static inline void
vcom_fd_set_merge (
- /* dest, select sets */
- int *nfds,
- fd_set * __restrict readfds,
- fd_set * __restrict writefds,
- fd_set * __restrict exceptfds, int *nfd,
- /* src1, vcom sets */
- int vcom_nfds,
- fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds, int vcom_nfd,
- /* src2, libc sets */
- int libc_nfds,
- fd_set * __restrict libc_readfds,
- fd_set * __restrict libc_writefds,
- fd_set * __restrict libc_exceptfds, int libc_nfd)
+ /* dest, select sets */
+ int *nfds,
+ fd_set * __restrict readfds,
+ fd_set * __restrict writefds,
+ fd_set * __restrict exceptfds, int *nfd,
+ /* src1, vcom sets */
+ int vcom_nfds,
+ fd_set * __restrict vcom_readfds,
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds, int vcom_nfd,
+ /* src2, libc sets */
+ int libc_nfds,
+ fd_set * __restrict libc_readfds,
+ fd_set * __restrict libc_writefds,
+ fd_set * __restrict libc_exceptfds, int libc_nfd)
{
int fd;
/* invalid max_fd is -1 */
@@ -699,13 +706,13 @@ vcom_fd_set_merge (
/* source(vcom) to dest(select) rwe fd sets */
FD_RWE_SETS_OR (readfds, writefds, exceptfds,
- vcom_readfds, vcom_writefds, vcom_exceptfds,
- fd, vcom_nfds, max_fd, nfd2);
+ vcom_readfds, vcom_writefds, vcom_exceptfds,
+ fd, vcom_nfds, max_fd, nfd2);
/* source(libc) to dest(select) rwe fd sets */
FD_RWE_SETS_OR (readfds, writefds, exceptfds,
- libc_readfds, libc_writefds, libc_exceptfds,
- fd, libc_nfds, max_fd, nfd2);
+ libc_readfds, libc_writefds, libc_exceptfds,
+ fd, libc_nfds, max_fd, nfd2);
#undef FD_RWE_SETS_OR
#undef FD_BIT_OR
@@ -731,10 +738,10 @@ fd_set_iszero (fd_set * __restrict fds)
for (fd = 0; fd < FD_SETSIZE; fd++)
{
if (FD_ISSET (fd, fds))
- {
- /* non-empty fds */
- return 0;
- }
+ {
+ /* non-empty fds */
+ return 0;
+ }
}
/* empty fds */
return 1;
@@ -806,7 +813,7 @@ timeval_compare (const struct timeval *lhs, const struct timeval *rhs)
}
extern void set_normalized_timespec (struct timespec *ts, time_t sec,
- s64 nsec);
+ s64 nsec);
static inline struct timespec
@@ -814,7 +821,7 @@ timespec_add (struct timespec lhs, struct timespec rhs)
{
struct timespec ts_delta;
set_normalized_timespec (&ts_delta, lhs.tv_sec + rhs.tv_sec,
- lhs.tv_nsec + rhs.tv_nsec);
+ lhs.tv_nsec + rhs.tv_nsec);
return ts_delta;
}
@@ -826,7 +833,7 @@ timespec_sub (struct timespec lhs, struct timespec rhs)
{
struct timespec ts_delta;
set_normalized_timespec (&ts_delta, lhs.tv_sec - rhs.tv_sec,
- lhs.tv_nsec - rhs.tv_nsec);
+ lhs.tv_nsec - rhs.tv_nsec);
return ts_delta;
}
@@ -889,19 +896,19 @@ set_normalized_timespec (struct timespec *ts, time_t sec, s64 nsec)
static inline int
vcom_select_impl (int vcom_nfds, fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds,
- struct timeval *__restrict timeout)
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds,
+ struct timeval *__restrict timeout)
{
return vcom_socket_select (vcom_nfds, vcom_readfds,
- vcom_writefds, vcom_exceptfds, timeout);
+ vcom_writefds, vcom_exceptfds, timeout);
}
int
vcom_select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout)
{
int rv;
int rv2 = 0;
@@ -942,17 +949,17 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
/* validate tv_sec */
/* bogus */
if (!vcom_timerisvalid (__timeout))
- {
- rv = -EINVAL;
- goto select_done;
- }
+ {
+ rv = -EINVAL;
+ goto select_done;
+ }
/* validate tv_usec */
/* TBD: */
/* init timeout_ts */
VCOM_TIMEVAL_TO_TIMESPEC (__timeout, &timeout_ts);
set_normalized_timespec (&timeout_ts,
- timeout_ts.tv_sec, timeout_ts.tv_nsec);
+ timeout_ts.tv_sec, timeout_ts.tv_nsec);
}
rv = clock_gettime (CLOCK_MONOTONIC, &start_time);
@@ -967,17 +974,17 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
if (__timeout)
{
if (timerisset (__timeout))
- {
- end_time = timespec_add (start_time, timeout_ts);
- }
+ {
+ end_time = timespec_add (start_time, timeout_ts);
+ }
else
- {
- /*
- * if both fields of the timeout structure are zero,
- * then select returns immediately
- * */
- end_time = start_time;
- }
+ {
+ /*
+ * if both fields of the timeout structure are zero,
+ * then select returns immediately
+ * */
+ end_time = start_time;
+ }
}
else
{
@@ -1014,17 +1021,17 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
(!__exceptfds || fd_set_iszero (__exceptfds)))
{
if (__timeout)
- {
- rv = libc_select (__nfds,
- __readfds, __writefds, __exceptfds, __timeout);
- if (rv == -1)
- rv = -errno;
- }
+ {
+ rv = libc_select (__nfds,
+ __readfds, __writefds, __exceptfds, __timeout);
+ if (rv == -1)
+ rv = -errno;
+ }
else
- {
- /* TBD: block indefinitely or return -EINVAL */
- rv = -EINVAL;
- }
+ {
+ /* TBD: block indefinitely or return -EINVAL */
+ rv = -EINVAL;
+ }
goto select_done;
}
@@ -1057,24 +1064,24 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
libc_nfd = -1;
vcom_fd_set_split (
- /* src, select sets */
- __nfds, __readfds, __writefds, __exceptfds,
- /* dest1, vcom sets */
- __readfds || __writefds || __exceptfds ?
- &vcom_nfds : NULL,
- __readfds ? &vcom_readfds : NULL,
- __writefds ? &vcom_writefds : NULL,
- __exceptfds ? &vcom_exceptfds : NULL,
- __readfds || __writefds || __exceptfds ?
- &vcom_nfd : NULL,
- /* dest2, libc sets */
- __readfds || __writefds || __exceptfds ?
- &libc_nfds : NULL,
- __readfds ? &libc_readfds : NULL,
- __writefds ? &libc_writefds : NULL,
- __exceptfds ? &libc_exceptfds : NULL,
- __readfds || __writefds || __exceptfds ?
- &libc_nfd : NULL);
+ /* src, select sets */
+ __nfds, __readfds, __writefds, __exceptfds,
+ /* dest1, vcom sets */
+ __readfds || __writefds || __exceptfds ?
+ &vcom_nfds : NULL,
+ __readfds ? &vcom_readfds : NULL,
+ __writefds ? &vcom_writefds : NULL,
+ __exceptfds ? &vcom_exceptfds : NULL,
+ __readfds || __writefds || __exceptfds ?
+ &vcom_nfd : NULL,
+ /* dest2, libc sets */
+ __readfds || __writefds || __exceptfds ?
+ &libc_nfds : NULL,
+ __readfds ? &libc_readfds : NULL,
+ __writefds ? &libc_writefds : NULL,
+ __exceptfds ? &libc_exceptfds : NULL,
+ __readfds || __writefds || __exceptfds ?
+ &libc_nfd : NULL);
/*
* polling loop
@@ -1098,52 +1105,52 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
/* select on vcom fds */
if (vcom_nfds)
- {
- vcom_nfd = vcom_select_impl (vcom_nfds,
- __readfds ? &vcom_readfds : NULL,
- __writefds ? &vcom_writefds : NULL,
- __exceptfds ? &vcom_exceptfds : NULL,
- &tv);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] select vcom: "
- "'%04d'='%04d'\n", pid, vcom_nfd, vcom_nfds);
-
- if (vcom_nfd < 0)
- {
- rv = vcom_nfd;
- goto select_done;
- }
- }
+ {
+ vcom_nfd = vcom_select_impl (vcom_nfds,
+ __readfds ? &vcom_readfds : NULL,
+ __writefds ? &vcom_writefds : NULL,
+ __exceptfds ? &vcom_exceptfds : NULL,
+ &tv);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] select vcom: "
+ "'%04d'='%04d'\n", pid, vcom_nfd, vcom_nfds);
+
+ if (vcom_nfd < 0)
+ {
+ rv = vcom_nfd;
+ goto select_done;
+ }
+ }
/* select on libc fds */
if (libc_nfds)
- {
- libc_nfd = libc_select (libc_nfds,
- __readfds ? &libc_readfds : NULL,
- __writefds ? &libc_writefds : NULL,
- __exceptfds ? &libc_exceptfds : NULL, &tv);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] select libc: "
- "'%04d'='%04d'\n", pid, libc_nfd, libc_nfds);
-
- if (libc_nfd < 0)
- {
- /* tv becomes undefined */
- libc_nfd = errno;
- rv = libc_nfd;
- goto select_done;
- }
- }
+ {
+ libc_nfd = libc_select (libc_nfds,
+ __readfds ? &libc_readfds : NULL,
+ __writefds ? &libc_writefds : NULL,
+ __exceptfds ? &libc_exceptfds : NULL, &tv);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] select libc: "
+ "'%04d'='%04d'\n", pid, libc_nfd, libc_nfds);
+
+ if (libc_nfd < 0)
+ {
+ /* tv becomes undefined */
+ libc_nfd = errno;
+ rv = libc_nfd;
+ goto select_done;
+ }
+ }
/* check if any file descriptors changed status */
if ((vcom_nfds && vcom_nfd > 0) || (libc_nfds && libc_nfd > 0))
- {
- /* zero the sets before merge and exit */
+ {
+ /* zero the sets before merge and exit */
- /*
- * F fd set
- */
+ /*
+ * F fd set
+ */
#define _(F) \
if ((F)) \
{ \
@@ -1151,60 +1158,60 @@ vcom_select (int __nfds, fd_set * __restrict __readfds,
}
- _(__readfds);
- _(__writefds);
- _(__exceptfds);
+ _(__readfds);
+ _(__writefds);
+ _(__exceptfds);
#undef _
- new_nfds = 0;
- new_nfd = -1;
-
- /*
- * on exit, sets are modified in place to indicate which
- * file descriptors actually changed status
- * */
- vcom_fd_set_merge (
- /* dest, select sets */
- __readfds || __writefds || __exceptfds ?
- &new_nfds : NULL,
- __readfds,
- __writefds,
- __exceptfds,
- __readfds || __writefds || __exceptfds ?
- &new_nfd : NULL,
- /* src1, vcom sets */
- vcom_nfds,
- __readfds ? &vcom_readfds : NULL,
- __writefds ? &vcom_writefds : NULL,
- __exceptfds ? &vcom_exceptfds : NULL, vcom_nfd,
- /* src2, libc sets */
- libc_nfds,
- __readfds ? &libc_readfds : NULL,
- __writefds ? &libc_writefds : NULL,
- __exceptfds ? &libc_exceptfds : NULL, libc_nfd);
- /*
- * return the number of file descriptors contained in the
- * three returned sets
- * */
- rv = 0;
- /*
- * for documentation
- *
- * if(vcom_nfd > 0)
- * rv += vcom_nfd;
- * if(libc_nfd > 0)
- * rv += libc_nfd;
- */
-
- rv = new_nfd == -1 ? 0 : new_nfd;
- goto select_done;
- }
+ new_nfds = 0;
+ new_nfd = -1;
+
+ /*
+ * on exit, sets are modified in place to indicate which
+ * file descriptors actually changed status
+ * */
+ vcom_fd_set_merge (
+ /* dest, select sets */
+ __readfds || __writefds || __exceptfds ?
+ &new_nfds : NULL,
+ __readfds,
+ __writefds,
+ __exceptfds,
+ __readfds || __writefds || __exceptfds ?
+ &new_nfd : NULL,
+ /* src1, vcom sets */
+ vcom_nfds,
+ __readfds ? &vcom_readfds : NULL,
+ __writefds ? &vcom_writefds : NULL,
+ __exceptfds ? &vcom_exceptfds : NULL, vcom_nfd,
+ /* src2, libc sets */
+ libc_nfds,
+ __readfds ? &libc_readfds : NULL,
+ __writefds ? &libc_writefds : NULL,
+ __exceptfds ? &libc_exceptfds : NULL, libc_nfd);
+ /*
+ * return the number of file descriptors contained in the
+ * three returned sets
+ * */
+ rv = 0;
+ /*
+ * for documentation
+ *
+ * if(vcom_nfd > 0)
+ * rv += vcom_nfd;
+ * if(libc_nfd > 0)
+ * rv += libc_nfd;
+ */
+
+ rv = new_nfd == -1 ? 0 : new_nfd;
+ goto select_done;
+ }
rv = clock_gettime (CLOCK_MONOTONIC, &now);
if (rv == -1)
- {
- rv = -errno;
- goto select_done;
- }
+ {
+ rv = -errno;
+ goto select_done;
+ }
}
while (no_timeout || timespec_compare (&now, &end_time) < 0);
@@ -1221,27 +1228,27 @@ select_done:
if (__timeout)
{
if (vcom_timerisvalid (__timeout))
- {
- /* timeout expired */
- if (timedout)
- {
- timerclear (__timeout);
- }
- else if (!first_clock_gettime_failed)
- {
- rv2 = clock_gettime (CLOCK_MONOTONIC, &now);
- if (rv2 == -1)
- {
- rv = -errno;
- }
- else
- {
- struct timespec ts_delta;
- ts_delta = timespec_sub (end_time, now);
- VCOM_TIMESPEC_TO_TIMEVAL (__timeout, &ts_delta);
- }
- }
- }
+ {
+ /* timeout expired */
+ if (timedout)
+ {
+ timerclear (__timeout);
+ }
+ else if (!first_clock_gettime_failed)
+ {
+ rv2 = clock_gettime (CLOCK_MONOTONIC, &now);
+ if (rv2 == -1)
+ {
+ rv = -errno;
+ }
+ else
+ {
+ struct timespec ts_delta;
+ ts_delta = timespec_sub (end_time, now);
+ VCOM_TIMESPEC_TO_TIMEVAL (__timeout, &ts_delta);
+ }
+ }
+ }
}
if (VCOM_DEBUG > 0)
fprintf (stderr, "[%d] vselect2: " "'%04d',='%04d'\n", pid, rv, __nfds);
@@ -1251,9 +1258,9 @@ select_done:
int
vcom_select_internal (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout)
{
int rv;
int new_nfds = 0;
@@ -1277,10 +1284,10 @@ vcom_select_internal (int __nfds, fd_set * __restrict __readfds,
/* validate tv_sec */
/* bogus */
if (__timeout->tv_sec < 0 || __timeout->tv_usec < 0)
- {
- errno = EINVAL;
- return -1;
- }
+ {
+ errno = EINVAL;
+ return -1;
+ }
/* validate tv_usec */
/* TBD: */
@@ -1333,28 +1340,28 @@ vcom_select_internal (int __nfds, fd_set * __restrict __readfds,
/* have kernel fds */
if (new_nfds)
rv = libc_select (new_nfds, __readfds,
- __writefds, __exceptfds, __timeout);
+ __writefds, __exceptfds, __timeout);
if (new_nfds && rv == -1)
{
/* on error, the file descriptor sets are unmodified */
if (__readfds)
- *__readfds = saved_readfds;
+ *__readfds = saved_readfds;
if (__writefds)
- *__writefds = saved_writefds;
+ *__writefds = saved_writefds;
if (__exceptfds)
- *__exceptfds = saved_exceptfds;
+ *__exceptfds = saved_exceptfds;
return rv;
}
else if ((new_nfds && rv != -1) || (rv == -2))
{
/* restore vcom fds */
nfd = vcom_fd_set (__nfds,
- &new_nfds,
- __readfds,
- __writefds,
- __exceptfds,
- &saved_readfds, &saved_writefds, &saved_exceptfds);
+ &new_nfds,
+ __readfds,
+ __writefds,
+ __exceptfds,
+ &saved_readfds, &saved_writefds, &saved_exceptfds);
rv = nfd;
}
@@ -1365,8 +1372,8 @@ vcom_select_internal (int __nfds, fd_set * __restrict __readfds,
int
select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds, struct timeval *__restrict __timeout)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds, struct timeval *__restrict __timeout)
{
int rv = 0;
pid_t pid = getpid ();
@@ -1395,10 +1402,10 @@ select (int __nfds, fd_set * __restrict __readfds,
* */
int
vcom_pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask)
{
int fd;
int vcom_nfds = 0;
@@ -1406,37 +1413,37 @@ vcom_pselect (int __nfds, fd_set * __restrict __readfds,
for (fd = 0; fd < __nfds; fd++)
{
if (__readfds && FD_ISSET (fd, __readfds))
- {
- if (is_vcom_socket_fd (fd))
- {
- vcom_nfds++;
- }
- }
+ {
+ if (is_vcom_socket_fd (fd))
+ {
+ vcom_nfds++;
+ }
+ }
if (__writefds && FD_ISSET (fd, __writefds))
- {
- if (is_vcom_socket_fd (fd))
- {
- vcom_nfds++;
- }
- }
+ {
+ if (is_vcom_socket_fd (fd))
+ {
+ vcom_nfds++;
+ }
+ }
if (__exceptfds && FD_ISSET (fd, __exceptfds))
- {
- if (is_vcom_socket_fd (fd))
- {
- FD_CLR (fd, __exceptfds);
- }
- }
+ {
+ if (is_vcom_socket_fd (fd))
+ {
+ FD_CLR (fd, __exceptfds);
+ }
+ }
}
return vcom_nfds;
}
int
pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask)
{
int rv;
int new_nfds = 0;
@@ -1460,10 +1467,10 @@ pselect (int __nfds, fd_set * __restrict __readfds,
/* validate tv_sec */
/* bogus */
if (__timeout->tv_sec < 0 || __timeout->tv_nsec < 0)
- {
- errno = EINVAL;
- return -1;
- }
+ {
+ errno = EINVAL;
+ return -1;
+ }
/* validate tv_usec */
/* TBD: */
@@ -1515,29 +1522,29 @@ pselect (int __nfds, fd_set * __restrict __readfds,
rv = -2;
if (new_nfds)
rv = libc_pselect (new_nfds,
- __readfds,
- __writefds, __exceptfds, __timeout, __sigmask);
+ __readfds,
+ __writefds, __exceptfds, __timeout, __sigmask);
if (new_nfds && rv == -1)
{
/* on error, the file descriptor sets are unmodified */
if (__readfds)
- *__readfds = saved_readfds;
+ *__readfds = saved_readfds;
if (__writefds)
- *__writefds = saved_writefds;
+ *__writefds = saved_writefds;
if (__exceptfds)
- *__exceptfds = saved_exceptfds;
+ *__exceptfds = saved_exceptfds;
return rv;
}
else if ((new_nfds && rv != -1) || (rv == -2))
{
/* restore vcom fds */
nfd = vcom_fd_set (__nfds,
- &new_nfds,
- __readfds,
- __writefds,
- __exceptfds,
- &saved_readfds, &saved_writefds, &saved_exceptfds);
+ &new_nfds,
+ __readfds,
+ __writefds,
+ __exceptfds,
+ &saved_readfds, &saved_writefds, &saved_exceptfds);
rv = nfd;
}
@@ -1586,32 +1593,32 @@ socket (int __domain, int __type, int __protocol)
case AF_INET6:
/* handle types implemented by vpp */
switch (__type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
- {
- case SOCK_STREAM:
- case SOCK_DGRAM:
- if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
- rv = vcom_socket (__domain, __type, __protocol);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] socket: "
- "'%04d'= D='%04d', T='%04d', P='%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- rv, __domain, __type, __protocol);
- if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
- if (rv < 0)
- {
- errno = -rv;
- return -1;
- }
- return rv;
- break;
-
- default:
- goto CALL_GLIBC_SOCKET_API;
- break;
- }
+ {
+ case SOCK_STREAM:
+ case SOCK_DGRAM:
+ if (VCOM_DEBUG > 0)
+ vcom_socket_main_show ();
+ rv = vcom_socket (__domain, __type, __protocol);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] socket: "
+ "'%04d'= D='%04d', T='%04d', P='%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ rv, __domain, __type, __protocol);
+ if (VCOM_DEBUG > 0)
+ vcom_socket_main_show ();
+ if (rv < 0)
+ {
+ errno = -rv;
+ return -1;
+ }
+ return rv;
+ break;
+
+ default:
+ goto CALL_GLIBC_SOCKET_API;
+ break;
+ }
break;
@@ -1655,27 +1662,27 @@ socketpair (int __domain, int __type, int __protocol, int __fds[2])
case AF_INET6:
/* handle types implemented by vpp */
switch (__type)
- {
- case SOCK_STREAM:
- case SOCK_DGRAM:
- rv = vcom_socketpair (__domain, __type, __protocol, __fds);
- if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] socketpair: "
- "'%04d'= D='%04d', T='%04d', P='%04d'\n",
- pid, rv, __domain, __type, __protocol);
- if (rv < 0)
- {
- errno = -rv;
- return -1;
- }
- return 0;
- break;
-
- default:
- goto CALL_GLIBC_SOCKET_API;
- break;
- }
+ {
+ case SOCK_STREAM:
+ case SOCK_DGRAM:
+ rv = vcom_socketpair (__domain, __type, __protocol, __fds);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] socketpair: "
+ "'%04d'= D='%04d', T='%04d', P='%04d'\n",
+ pid, rv, __domain, __type, __protocol);
+ if (rv < 0)
+ {
+ errno = -rv;
+ return -1;
+ }
+ return 0;
+ break;
+
+ default:
+ goto CALL_GLIBC_SOCKET_API;
+ break;
+ }
break;
@@ -1707,11 +1714,11 @@ vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
{
case AF_INET:
if (__len != sizeof (struct sockaddr_in))
- return -EINVAL;
+ return -EINVAL;
break;
case AF_INET6:
if (__len != sizeof (struct sockaddr_in6))
- return -EINVAL;
+ return -EINVAL;
break;
default:
@@ -1747,15 +1754,15 @@ bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
rv = vcom_bind (__fd, __addr, __len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] bind: "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, rv, __fd, __addr, __len);
+ fprintf (stderr,
+ "[%d] bind: "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, rv, __fd, __addr, __len);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_bind (__fd, __addr, __len);
@@ -1766,7 +1773,7 @@ bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
* */
int
vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len)
+ socklen_t * __restrict __len)
{
if (vcom_init () != 0)
{
@@ -1786,14 +1793,14 @@ getsockname (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len)
{
rv = vcom_getsockname (__fd, __addr, __len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] getsockname: "
- "'%04d'='%04d', '%p', '%p'\n", pid, rv, __fd, __addr, __len);
+ fprintf (stderr,
+ "[%d] getsockname: "
+ "'%04d'='%04d', '%p', '%p'\n", pid, rv, __fd, __addr, __len);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_getsockname (__fd, __addr, __len);
@@ -1822,11 +1829,11 @@ vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
{
case AF_INET:
if (__len != INET_ADDRSTRLEN)
- return -1;
+ return -1;
break;
case AF_INET6:
if (__len != INET6_ADDRSTRLEN)
- return -1;
+ return -1;
break;
default:
@@ -1861,16 +1868,16 @@ connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
{
rv = vcom_connect (__fd, __addr, __len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] connect: "
- "'%04d'='%04d', '%p', '%04d'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- rv, __fd, __addr, __len);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] connect: "
+ "'%04d'='%04d', '%p', '%04d'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ rv, __fd, __addr, __len);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
@@ -1883,7 +1890,7 @@ connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
* */
int
vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len)
+ socklen_t * __restrict __len)
{
if (vcom_init () != 0)
{
@@ -1903,14 +1910,14 @@ getpeername (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len)
{
rv = vcom_getpeername (__fd, __addr, __len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] getpeername: "
- "'%04d'='%04d', '%p', '%p'\n", pid, rv, __fd, __addr, __len);
+ fprintf (stderr,
+ "[%d] getpeername: "
+ "'%04d'='%04d', '%p', '%p'\n", pid, rv, __fd, __addr, __len);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_getpeername (__fd, __addr, __len);
@@ -1943,15 +1950,15 @@ send (int __fd, const void *__buf, size_t __n, int __flags)
{
size = vcom_send (__fd, __buf, __n, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] send: "
- "'%04d'='%04d', '%p', '%04d', '%04x'\n",
- pid, (int) size, __fd, __buf, (int) __n, __flags);
+ fprintf (stderr,
+ "[%d] send: "
+ "'%04d'='%04d', '%p', '%04d', '%04x'\n",
+ pid, (int) size, __fd, __buf, (int) __n, __flags);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_send (__fd, __buf, __n, __flags);
@@ -1984,15 +1991,15 @@ recv (int __fd, void *__buf, size_t __n, int __flags)
{
size = vcom_recv (__fd, __buf, __n, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] recv: "
- "'%04d'='%04d', '%p', '%04d', '%04x'\n",
- pid, (int) size, __fd, __buf, (int) __n, __flags);
+ fprintf (stderr,
+ "[%d] recv: "
+ "'%04d'='%04d', '%p', '%04d', '%04x'\n",
+ pid, (int) size, __fd, __buf, (int) __n, __flags);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_recv (__fd, __buf, __n, __flags);
@@ -2006,7 +2013,7 @@ recv (int __fd, void *__buf, size_t __n, int __flags)
* */
ssize_t
vcom_sendto (int __fd, const void *__buf, size_t __n, int __flags,
- __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len)
+ __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len)
{
if (vcom_init () != 0)
{
@@ -2018,7 +2025,7 @@ vcom_sendto (int __fd, const void *__buf, size_t __n, int __flags,
ssize_t
sendto (int __fd, const void *__buf, size_t __n, int __flags,
- __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len)
+ __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len)
{
ssize_t size;
pid_t pid = getpid ();
@@ -2027,17 +2034,17 @@ sendto (int __fd, const void *__buf, size_t __n, int __flags,
{
size = vcom_sendto (__fd, __buf, __n, __flags, __addr, __addr_len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] sendto: "
- "'%04d'='%04d', '%p', '%04d', '%04x', "
- "'%p', '%04d'\n",
- pid, (int) size, __fd, __buf, (int) __n, __flags,
- __addr, __addr_len);
+ fprintf (stderr,
+ "[%d] sendto: "
+ "'%04d'='%04d', '%p', '%04d', '%04x', "
+ "'%p', '%04d'\n",
+ pid, (int) size, __fd, __buf, (int) __n, __flags,
+ __addr, __addr_len);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_sendto (__fd, __buf, __n, __flags, __addr, __addr_len);
@@ -2054,8 +2061,8 @@ sendto (int __fd, const void *__buf, size_t __n, int __flags,
* */
ssize_t
vcom_recvfrom (int __fd, void *__restrict __buf, size_t __n,
- int __flags,
- __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
+ int __flags,
+ __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
{
if (vcom_init () != 0)
{
@@ -2067,8 +2074,8 @@ vcom_recvfrom (int __fd, void *__restrict __buf, size_t __n,
ssize_t
recvfrom (int __fd, void *__restrict __buf, size_t __n,
- int __flags,
- __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
+ int __flags,
+ __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
{
ssize_t size;
pid_t pid = getpid ();
@@ -2077,17 +2084,17 @@ recvfrom (int __fd, void *__restrict __buf, size_t __n,
{
size = vcom_recvfrom (__fd, __buf, __n, __flags, __addr, __addr_len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] recvfrom: "
- "'%04d'='%04d', '%p', '%04d', '%04x', "
- "'%p', '%p'\n",
- pid, (int) size, __fd, __buf, (int) __n, __flags,
- __addr, __addr_len);
+ fprintf (stderr,
+ "[%d] recvfrom: "
+ "'%04d'='%04d', '%p', '%04d', '%04x', "
+ "'%p', '%p'\n",
+ pid, (int) size, __fd, __buf, (int) __n, __flags,
+ __addr, __addr_len);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_recvfrom (__fd, __buf, __n, __flags, __addr, __addr_len);
@@ -2120,15 +2127,15 @@ sendmsg (int __fd, const struct msghdr * __message, int __flags)
{
size = vcom_sendmsg (__fd, __message, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] sendmsg: "
- "'%04d'='%04d', '%p', '%04x'\n",
- pid, (int) size, __fd, __message, __flags);
+ fprintf (stderr,
+ "[%d] sendmsg: "
+ "'%04d'='%04d', '%p', '%04x'\n",
+ pid, (int) size, __fd, __message, __flags);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_sendmsg (__fd, __message, __flags);
@@ -2144,7 +2151,7 @@ sendmsg (int __fd, const struct msghdr * __message, int __flags)
* */
int
vcom_sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags)
+ unsigned int __vlen, int __flags)
{
if (vcom_init () != 0)
{
@@ -2156,7 +2163,7 @@ vcom_sendmmsg (int __fd, struct mmsghdr *__vmessages,
int
sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags)
+ unsigned int __vlen, int __flags)
{
ssize_t size;
pid_t pid = getpid ();
@@ -2165,15 +2172,15 @@ sendmmsg (int __fd, struct mmsghdr *__vmessages,
{
size = vcom_sendmmsg (__fd, __message, __vlen, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] sendmmsg: "
- "'%04d'='%04d', '%p', '%04d', '%04x'\n",
- pid, (int) size, __fd, __vmessages, __vlen, __flags);
+ fprintf (stderr,
+ "[%d] sendmmsg: "
+ "'%04d'='%04d', '%p', '%04d', '%04x'\n",
+ pid, (int) size, __fd, __vmessages, __vlen, __flags);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_sendmmsg (__fd, __message, __vlen, __flags);
@@ -2208,15 +2215,15 @@ recvmsg (int __fd, struct msghdr * __message, int __flags)
{
size = vcom_recvmsg (__fd, __message, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] recvmsg: "
- "'%04d'='%04d', '%p', '%04x'\n",
- pid, (int) size, __fd, __message, __flags);
+ fprintf (stderr,
+ "[%d] recvmsg: "
+ "'%04d'='%04d', '%p', '%04x'\n",
+ pid, (int) size, __fd, __message, __flags);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_recvmsg (__fd, __message, __flags);
@@ -2231,7 +2238,7 @@ recvmsg (int __fd, struct msghdr * __message, int __flags)
* */
int
vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags, struct timespec *__tmo)
+ unsigned int __vlen, int __flags, struct timespec *__tmo)
{
if (vcom_init () != 0)
{
@@ -2243,7 +2250,7 @@ vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
int
recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags, struct timespec *__tmo)
+ unsigned int __vlen, int __flags, struct timespec *__tmo)
{
ssize_t size;
pid_t pid = getpid ();
@@ -2252,16 +2259,16 @@ recvmmsg (int __fd, struct mmsghdr *__vmessages,
{
size = vcom_recvmmsg (__fd, __message, __vlen, __flags, __tmo);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] recvmmsg: "
- "'%04d'='%04d', '%p', "
- "'%04d', '%04x', '%p'\n",
- pid, (int) size, __fd, __vmessages, __vlen, __flags, __tmo);
+ fprintf (stderr,
+ "[%d] recvmmsg: "
+ "'%04d'='%04d', '%p', "
+ "'%04d', '%04x', '%p'\n",
+ pid, (int) size, __fd, __vmessages, __vlen, __flags, __tmo);
if (size < 0)
- {
- errno = -size;
- return -1;
- }
+ {
+ errno = -size;
+ return -1;
+ }
return size;
}
return libc_recvmmsg (__fd, __message, __vlen, __flags, __tmo);
@@ -2277,7 +2284,7 @@ recvmmsg (int __fd, struct mmsghdr *__vmessages,
* */
int
vcom_getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval, socklen_t * __restrict __optlen)
+ void *__restrict __optval, socklen_t * __restrict __optlen)
{
if (vcom_init () != 0)
{
@@ -2285,12 +2292,12 @@ vcom_getsockopt (int __fd, int __level, int __optname,
}
return vcom_socket_getsockopt (__fd, __level, __optname,
- __optval, __optlen);
+ __optval, __optlen);
}
int
getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval, socklen_t * __restrict __optlen)
+ void *__restrict __optval, socklen_t * __restrict __optlen)
{
int rv;
pid_t pid = getpid ();
@@ -2299,16 +2306,16 @@ getsockopt (int __fd, int __level, int __optname,
{
rv = vcom_getsockopt (__fd, __level, __optname, __optval, __optlen);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] getsockopt: "
- "'%04d'='%04d', '%04d', '%04d', "
- "'%p', '%p'\n",
- pid, rv, __fd, __level, __optname, __optval, __optlen);
+ fprintf (stderr,
+ "[%d] getsockopt: "
+ "'%04d'='%04d', '%04d', '%04d', "
+ "'%p', '%p'\n",
+ pid, rv, __fd, __level, __optname, __optval, __optlen);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_getsockopt (__fd, __level, __optname, __optval, __optlen);
@@ -2321,7 +2328,7 @@ getsockopt (int __fd, int __level, int __optname,
* */
int
vcom_setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen)
+ const void *__optval, socklen_t __optlen)
{
if (vcom_init () != 0)
{
@@ -2329,12 +2336,12 @@ vcom_setsockopt (int __fd, int __level, int __optname,
}
return vcom_socket_setsockopt (__fd, __level, __optname,
- __optval, __optlen);
+ __optval, __optlen);
}
int
setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen)
+ const void *__optval, socklen_t __optlen)
{
int rv;
pid_t pid = getpid ();
@@ -2343,16 +2350,16 @@ setsockopt (int __fd, int __level, int __optname,
{
rv = vcom_setsockopt (__fd, __level, __optname, __optval, __optlen);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] setsockopt: "
- "'%04d'='%04d', '%04d', '%04d', "
- "'%p', '%04d'\n",
- pid, rv, __fd, __level, __optname, __optval, __optlen);
+ fprintf (stderr,
+ "[%d] setsockopt: "
+ "'%04d'='%04d', '%04d', '%04d', "
+ "'%p', '%04d'\n",
+ pid, rv, __fd, __level, __optname, __optval, __optlen);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_setsockopt (__fd, __level, __optname, __optval, __optlen);
@@ -2385,14 +2392,14 @@ listen (int __fd, int __n)
{
rv = vcom_listen (__fd, __n);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] listen: "
- "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __n);
+ fprintf (stderr,
+ "[%d] listen: "
+ "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __n);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_listen (__fd, __n);
@@ -2409,7 +2416,7 @@ listen (int __fd, int __n)
* */
int
vcom_accept (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len)
+ socklen_t * __restrict __addr_len)
{
if (vcom_init () != 0)
@@ -2429,27 +2436,27 @@ accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] accept1: "
- "'%04d'='%04d', '%p', '%p'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- rv, __fd, __addr, __addr_len);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] accept1: "
+ "'%04d'='%04d', '%p', '%p'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ rv, __fd, __addr, __addr_len);
rv = vcom_accept (__fd, __addr, __addr_len);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d][%lu (0x%lx)] accept2: "
- "'%04d'='%04d', '%p', '%p'\n",
- pid, (unsigned long) tid, (unsigned long) tid,
- rv, __fd, __addr, __addr_len);
+ fprintf (stderr,
+ "[%d][%lu (0x%lx)] accept2: "
+ "'%04d'='%04d', '%p', '%p'\n",
+ pid, (unsigned long) tid, (unsigned long) tid,
+ rv, __fd, __addr, __addr_len);
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
if (rv < 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return rv;
}
return libc_accept (__fd, __addr, __addr_len);
@@ -2464,7 +2471,7 @@ accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len)
* */
int
vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags)
+ socklen_t * __restrict __addr_len, int __flags)
{
if (vcom_init () != 0)
@@ -2477,7 +2484,7 @@ vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
int
accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags)
+ socklen_t * __restrict __addr_len, int __flags)
{
int rv;
pid_t pid = getpid ();
@@ -2485,20 +2492,20 @@ accept4 (int __fd, __SOCKADDR_ARG __addr,
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
rv = vcom_accept4 (__fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] accept4: "
- "'%04d'='%04d', '%p', '%p', '%04x'\n",
- pid, rv, __fd, __addr, __addr_len, __flags);
+ fprintf (stderr,
+ "[%d] accept4: "
+ "'%04d'='%04d', '%p', '%p', '%04x'\n",
+ pid, rv, __fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
- vcom_socket_main_show ();
+ vcom_socket_main_show ();
if (rv < 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return rv;
}
return libc_accept4 (__fd, __addr, __addr_len, __flags);
@@ -2534,19 +2541,273 @@ shutdown (int __fd, int __how)
{
rv = vcom_shutdown (__fd, __how);
if (VCOM_DEBUG > 0)
- fprintf (stderr,
- "[%d] shutdown: "
- "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __how);
+ fprintf (stderr,
+ "[%d] shutdown: "
+ "'%04d'='%04d', '%04d'\n", pid, rv, __fd, __how);
if (rv != 0)
- {
- errno = -rv;
- return -1;
- }
+ {
+ errno = -rv;
+ return -1;
+ }
return 0;
}
return libc_shutdown (__fd, __how);
}
+int
+vcom_epoll_create (int __size)
+{
+
+ if (vcom_init () != 0)
+ {
+ return -1;
+ }
+
+ if (__size <= 0)
+ {
+ return -EINVAL;
+ }
+
+ /* __size argument is ignored "thereafter" */
+ return vcom_epoll_create1(0);
+}
+
+/*
+ * __size argument is ignored, but must be greater than zero
+ */
+int
+epoll_create (int __size)
+{
+ int rv = 0;
+
+ rv = vcom_epoll_create(__size);
+ if (rv < 0)
+ {
+ errno = -rv;
+ return -1;
+ }
+ return rv;
+}
+
+int
+vcom_epoll_create1 (int __flags)
+{
+ if (vcom_init () != 0)
+ {
+ return -1;
+ }
+
+ if (__flags < 0)
+ {
+ return -EINVAL;
+ }
+ if (__flags & ~EPOLL_CLOEXEC)
+ {
+ return -EINVAL;
+ }
+ /* __flags can be either zero or EPOLL_CLOEXEC */
+ /* implementation */
+ return vcom_socket_epoll_create1(__flags);
+}
+
+/*
+ * __flags can be either zero or EPOLL_CLOEXEC
+ * */
+int
+epoll_create1 (int __flags)
+{
+ int rv = 0;
+
+ rv = vcom_epoll_create1(__flags);
+ if (rv < 0)
+ {
+ errno = -rv;
+ return -1;
+ }
+ return rv;
+}
+
+int
+vcom_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event)
+{
+ if (vcom_init () != 0)
+ {
+ return -1;
+ }
+
+ /* implementation */
+ return vcom_socket_epoll_ctl (__epfd, __op, __fd,
+ __event);
+}
+
+static inline int
+ep_op_has_event (int op)
+{
+ return op != EPOLL_CTL_DEL;
+}
+
+int
+epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event)
+{
+ int rv;
+ pid_t pid = getpid ();
+
+ if ((ep_op_has_event (__op) && !__event))
+ {
+ errno = EFAULT;
+ return -1;
+ }
+ 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 */
+ errno = EBADF;
+ return -1;
+ }
+ }
+ else
+ {
+ errno = EINVAL;
+ 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)
+{
+ int rv;
+ pid_t pid = getpid ();
+
+ if (__maxevents <=0 || __maxevents > EP_MAX_EVENTS)
+ {
+ 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 0;
+ }
+ else
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ return 0;
+}
+
+
+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)
+{
+ int rv;
+ pid_t pid = getpid ();
+
+ if (__maxevents <=0 || __maxevents > EP_MAX_EVENTS)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (is_vcom_epfd (__epfd))
+ {
+ rv = vcom_epoll_pwait (__epfd, __events,
+ __maxevents, __timeout,
+ __ss);
+ if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] epoll_pwait: "
+ "'%04d'='%04d', '%p', "
+ "'%04d', '%04d', "
+ "'%p'\n",
+ pid,
+ rv, __epfd, __events,
+ __maxevents, __timeout,
+ __ss);
+ if (rv != 0)
+ {
+ errno = -rv;
+ return -1;
+ }
+ return 0;
+ }
+ else
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ return 0;
+}
+
void CONSTRUCTOR_ATTRIBUTE vcom_constructor (void);
void DESTRUCTOR_ATTRIBUTE vcom_destructor (void);
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom.h b/vcl-ldpreload/src/libvcl-ldpreload/vcom.h
index 445d8af..d751fe1 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom.h
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom.h
@@ -54,17 +54,17 @@ extern int vcom_fcntl (int __fd, int __cmd, ...);
*/
extern int
vcom_select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout);
#ifdef __USE_XOPEN2K
extern int
vcom_pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask);
#endif
/*
@@ -85,14 +85,14 @@ vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
extern int __THROW
vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len);
+ socklen_t * __restrict __len);
extern int
vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
extern int __THROW
vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len);
+ socklen_t * __restrict __len);
extern ssize_t
vcom_send (int __fd, const void *__buf, size_t __n, int __flags);
@@ -101,12 +101,12 @@ extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
extern ssize_t
vcom_sendto (int __fd, const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
+ int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
extern ssize_t
vcom_recvfrom (int __fd, void *__restrict __buf,
- size_t __n, int __flags,
- __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
+ size_t __n, int __flags,
+ __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
extern ssize_t
vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
@@ -114,7 +114,7 @@ vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
#ifdef __USE_GNU
extern int
sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags);
+ unsigned int __vlen, int __flags);
#endif
extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
@@ -122,22 +122,22 @@ extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
#ifdef __USE_GNU
extern int
vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags, struct timespec *__tmo);
+ unsigned int __vlen, int __flags, struct timespec *__tmo);
#endif
extern int __THROW
vcom_getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval, socklen_t * __restrict __optlen);
+ void *__restrict __optval, socklen_t * __restrict __optlen);
extern int __THROW
vcom_setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen);
+ const void *__optval, socklen_t __optlen);
extern int __THROW vcom_listen (int __fd, int __n);
extern int
vcom_accept (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len);
+ socklen_t * __restrict __addr_len);
#ifdef __USE_GNU
/*
@@ -147,11 +147,31 @@ vcom_accept (int __fd, __SOCKADDR_ARG __addr,
/* TBD: implemented later */
extern int
vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags);
+ socklen_t * __restrict __addr_len, int __flags);
#endif
extern int __THROW vcom_shutdown (int __fd, int __how);
+extern int __THROW
+vcom_epoll_create (int __size);
+
+extern int __THROW
+vcom_epoll_create1 (int __flags);
+
+extern int __THROW
+vcom_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event);
+
+extern int
+vcom_epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+extern int
+vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss);
+
+
#endif /* included_vcom_h */
/*
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h b/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h
index 3e43a42..3ca1951 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_glibc_socket.h
@@ -22,6 +22,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
+#include <sys/epoll.h>
/*
*
* Generic glibc fd api
@@ -78,9 +79,9 @@ extern int fcntl (int __fd, int __cmd, ...);
__THROW. */
extern int
select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout);
#ifdef __USE_XOPEN2K
/* Same as above only that the TIMEOUT value is given with higher
@@ -91,10 +92,10 @@ select (int __nfds, fd_set * __restrict __readfds,
__THROW. */
extern int
pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask);
#endif
@@ -162,7 +163,7 @@ extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
__THROW. */
extern ssize_t
sendto (int __fd, const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
+ int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
/* Read N bytes into BUF through socket FD.
If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
@@ -173,8 +174,8 @@ sendto (int __fd, const void *__buf, size_t __n,
__THROW. */
extern ssize_t
recvfrom (int __fd, void *__restrict __buf,
- size_t __n, int __flags,
- __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
+ size_t __n, int __flags,
+ __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
/* Send a message described MESSAGE on socket FD.
Returns the number of bytes sent, or -1 for errors.
@@ -192,7 +193,7 @@ sendmsg (int __fd, const struct msghdr *__message, int __flags);
__THROW. */
extern int
sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags);
+ unsigned int __vlen, int __flags);
#endif
/* Receive a message as described by MESSAGE from socket FD.
@@ -210,7 +211,7 @@ extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
__THROW. */
extern int
recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags, struct timespec *__tmo);
+ unsigned int __vlen, int __flags, struct timespec *__tmo);
#endif
@@ -219,14 +220,14 @@ recvmmsg (int __fd, struct mmsghdr *__vmessages,
actual length. Returns 0 on success, -1 for errors. */
extern int __THROW
getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval, socklen_t * __restrict __optlen);
+ void *__restrict __optval, socklen_t * __restrict __optlen);
/* Set socket FD's option OPTNAME at protocol level LEVEL
to *OPTVAL (which is OPTLEN bytes long).
Returns 0 on success, -1 for errors. */
extern int __THROW
setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen);
+ const void *__optval, socklen_t __optlen);
/* Prepare to accept connections on socket FD.
N connection requests will be queued before further requests are refused.
@@ -252,7 +253,7 @@ accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
/* TBD: implemented later */
extern int
accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags);
+ socklen_t * __restrict __addr_len, int __flags);
#endif
/* Shut down all or part of the connection open on socket FD.
@@ -263,6 +264,60 @@ accept4 (int __fd, __SOCKADDR_ARG __addr,
Returns 0 on success, -1 for errors. */
extern int __THROW shutdown (int __fd, int __how);
+
+/*
+ * glibc APIs from <sys/epoll.h>
+ */
+
+/* Creates an epoll instance. Returns an fd for the new instance.
+ The "size" parameter is a hint specifying the number of file
+ descriptors to be associated with the new instance. The fd
+ returned by epoll_create() should be closed with close(). */
+extern int __THROW
+epoll_create (int __size);
+
+/* Same as epoll_create but with an FLAGS parameter. The unused SIZE
+ parameter has been dropped. */
+extern int __THROW
+epoll_create1 (int __flags);
+
+/* Manipulate an epoll instance "epfd". Returns 0 in case of success,
+ -1 in case of error ( the "errno" variable will contain the
+ specific error code ) The "op" parameter is one of the EPOLL_CTL_*
+ constants defined above. The "fd" parameter is the target of the
+ operation. The "event" parameter describes which events the caller
+ is interested in and any associated user data. */
+extern int __THROW
+epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event);
+
+#define INT_MAX ((int)(~0U>>1))
+#define EP_MAX_EVENTS (INT_MAX / sizeof(struct epoll_event))
+
+/* Wait for events on an epoll instance "epfd". Returns the number of
+ triggered events returned in "events" buffer. Or -1 in case of
+ error with the "errno" variable set to the specific error code. The
+ "events" parameter is a buffer that will contain triggered
+ events. The "maxevents" is the maximum number of events to be
+ returned ( usually size of "events" ). The "timeout" parameter
+ specifies the maximum wait time in milliseconds (-1 == infinite).
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int
+epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+/* Same as epoll_wait, but the thread's signal mask is temporarily
+ and atomically replaced with the one provided as parameter.
+
+ This function is a cancellation point and therefore not marked with
+ __THROW. */
+extern int
+epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss);
+
#endif /* included_vcom_glibc_socket_h */
/*
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c
index 8430ab1..42dff9b 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c
@@ -40,15 +40,26 @@ typedef struct vcom_socket_main_t_
/* Hash table for socketidx to fd mapping */
uword *sockidx_by_fd;
+ /* vcom_epoll pool */
+ vcom_epoll_t *vepolls;
+
+ /* Hash table for epollidx to epfd mapping */
+ uword *epollidx_by_epfd;
+
+ /* common epitem poll for all epfd */
+ /* TBD: epitem poll per epfd */
+ /* vcom_epitem pool */
+ vcom_epitem_t *vepitems;
+
+ /* Hash table for epitemidx to epfdfd mapping */
+ uword *epollidx_by_epfdfd;
+
} vcom_socket_main_t;
vcom_socket_main_t vcom_socket_main;
-/*
- * Public API functions
- */
-int
+static int
vcom_socket_open_socket (int domain, int type, int protocol)
{
int rv = -1;
@@ -61,22 +72,22 @@ vcom_socket_open_socket (int domain, int type, int protocol)
/* get socket type and
* handle the socket types supported by vpp */
switch (type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
- {
- case SOCK_STREAM:
- case SOCK_DGRAM:
- /* the type argument serves a second purpose,
- * in addition to specifying a socket type,
- * it may include the bitwise OR of any of
- * SOCK_NONBLOCK and SOCK_CLOEXEC, to modify
- * the behavior of socket. */
- rv = libc_socket (domain, type, protocol);
- if (rv == -1)
- rv = -errno;
- break;
-
- default:
- break;
- }
+ {
+ case SOCK_STREAM:
+ case SOCK_DGRAM:
+ /* the type argument serves a second purpose,
+ * in addition to specifying a socket type,
+ * it may include the bitwise OR of any of
+ * SOCK_NONBLOCK and SOCK_CLOEXEC, to modify
+ * the behavior of socket. */
+ rv = libc_socket (domain, type, protocol);
+ if (rv == -1)
+ rv = -errno;
+ break;
+
+ default:
+ break;
+ }
break;
@@ -87,7 +98,29 @@ vcom_socket_open_socket (int domain, int type, int protocol)
return rv;
}
-int
+static int
+vcom_socket_open_epoll (int flags)
+{
+ int rv = -1;
+
+ if (flags < 0)
+ {
+ return -EINVAL;
+ }
+ if (flags && (flags & ~EPOLL_CLOEXEC))
+ {
+ return -EINVAL;
+ }
+
+ /* flags can be either zero or EPOLL_CLOEXEC */
+ rv = libc_epoll_create1 (flags);
+ if (rv == -1)
+ rv = -errno;
+
+ return rv;
+}
+
+static int
vcom_socket_close_socket (int fd)
{
int rv;
@@ -99,6 +132,22 @@ vcom_socket_close_socket (int fd)
return rv;
}
+static int
+vcom_socket_close_epoll (int epfd)
+{
+ int rv;
+
+ rv = libc_close (epfd);
+ if (rv == -1)
+ rv = -errno;
+
+ return rv;
+}
+
+/*
+ * Public API functions
+ */
+
int
vcom_socket_main_init (void)
{
@@ -112,6 +161,10 @@ vcom_socket_main_init (void)
/* TBD: define FD_MAXSIZE and use it here */
pool_alloc (vsm->vsockets, FD_SETSIZE);
vsm->sockidx_by_fd = hash_create (0, sizeof (i32));
+
+ pool_alloc (vsm->vepolls, FD_SETSIZE);
+ vsm->epollidx_by_epfd = hash_create (0, sizeof (i32));
+
vsm->init = 1;
}
@@ -124,6 +177,8 @@ vcom_socket_main_destroy (void)
vcom_socket_main_t *vsm = &vcom_socket_main;
vcom_socket_t *vsock;
+ vcom_epoll_t *vepoll;
+
if (VCOM_DEBUG > 0)
printf ("vcom_socket_main_destroy\n");
@@ -160,6 +215,39 @@ vcom_socket_main_destroy (void)
pool_free (vsm->vsockets);
hash_free (vsm->sockidx_by_fd);
+
+ /*
+ * from active list of vepolls,
+ * close epoll and vppcom_epoll
+ * */
+
+ /* *INDENT-OFF* */
+ pool_foreach (vepoll, vsm->vepolls,
+ ({
+ if (vepoll->type == EPOLL_TYPE_VPPCOM_BOUND)
+ {
+ vppcom_session_close (vepoll->vep_idx);
+ vcom_socket_close_epoll (vepoll->epfd); /* TBD: */
+ vepoll_init (vepoll);
+ }
+ }));
+ /* *INDENT-ON* */
+
+ /*
+ * return vepoll element to the pool
+ * */
+
+ /* *INDENT-OFF* */
+ pool_flush (vepoll, vsm->vepolls,
+ ({
+ // vepoll_init(vepoll);
+ ;
+ }));
+ /* *INDENT-ON* */
+
+ pool_free (vsm->vepolls);
+ hash_free (vsm->epollidx_by_epfd);
+
vsm->init = 0;
}
}
@@ -170,6 +258,8 @@ vcom_socket_main_show (void)
vcom_socket_main_t *vsm = &vcom_socket_main;
vcom_socket_t *vsock;
+ vcom_epoll_t *vepoll;
+
if (vsm->init)
{
/* from active list of vsockets,
@@ -184,10 +274,25 @@ vcom_socket_main_show (void)
vcom_socket_type_str (vsock->type));
}));
/* *INDENT-ON* */
+
+ /* from active list of vepolls,
+ * close epoll and vppcom session */
+
+ /* *INDENT-OFF* */
+ pool_foreach (vepoll, vsm->vepolls,
+ ({
+ printf(
+ "epfd='%04d', vep_idx='%08x', "
+ "type='%-30s', "
+ "flags='%d', count='%d', close='%d'\n",
+ vepoll->epfd, vepoll->vep_idx,
+ vcom_socket_epoll_type_str (vepoll->type),
+ vepoll->flags, vepoll->count, vepoll->close);
+ }));
+ /* *INDENT-ON* */
}
}
-
int
vcom_socket_is_vcom_fd (int fd)
{
@@ -201,7 +306,25 @@ vcom_socket_is_vcom_fd (int fd)
{
vsock = pool_elt_at_index (vsm->vsockets, p[0]);
if (vsock && vsock->type == SOCKET_TYPE_VPPCOM_BOUND)
- return 1;
+ return 1;
+ }
+ return 0;
+}
+
+int
+vcom_socket_is_vcom_epfd (int epfd)
+{
+ vcom_socket_main_t *vsm = &vcom_socket_main;
+ uword *p;
+ vcom_epoll_t *vepoll;
+
+ p = hash_get (vsm->epollidx_by_epfd, epfd);
+
+ if (p)
+ {
+ vepoll = pool_elt_at_index (vsm->vepolls, p[0]);
+ if (vepoll && vepoll->type == EPOLL_TYPE_VPPCOM_BOUND)
+ return 1;
}
return 0;
}
@@ -219,20 +342,38 @@ vcom_socket_get_sid (int fd)
{
vsock = pool_elt_at_index (vsm->vsockets, p[0]);
if (vsock && vsock->type == SOCKET_TYPE_VPPCOM_BOUND)
- return vsock->sid;
+ return vsock->sid;
}
return INVALID_SESSION_ID;
}
-int
-vcom_socket_close (int __fd)
+static inline int
+vcom_socket_get_vep_idx (int epfd)
+{
+ vcom_socket_main_t *vsm = &vcom_socket_main;
+ uword *p;
+ vcom_epoll_t *vepoll;
+
+ p = hash_get (vsm->epollidx_by_epfd, epfd);
+
+ if (p)
+ {
+ vepoll = pool_elt_at_index (vsm->vepolls, p[0]);
+ if (vepoll && vepoll->type == EPOLL_TYPE_VPPCOM_BOUND)
+ return vepoll->vep_idx;
+ }
+ return INVALID_VEP_IDX;
+}
+
+static int
+vcom_socket_close_vsock (int fd)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
uword *p;
vcom_socket_t *vsock;
- p = hash_get (vsm->sockidx_by_fd, __fd);
+ p = hash_get (vsm->sockidx_by_fd, fd);
if (!p)
return -EBADF;
@@ -247,9 +388,79 @@ vcom_socket_close (int __fd)
rv = vcom_socket_close_socket (vsock->fd);
vsocket_init (vsock);
- hash_unset (vsm->sockidx_by_fd, __fd);
+ hash_unset (vsm->sockidx_by_fd, fd);
pool_put (vsm->vsockets, vsock);
+ /*
+ * TBD:
+ * close all epoll instances that are marked as "close"
+ * of which this fd is the last remaining member
+ * */
+
+ return rv;
+}
+
+int
+vcom_socket_close_vepoll (int epfd)
+{
+ int rv = -1;
+ vcom_socket_main_t *vsm = &vcom_socket_main;
+ uword *p;
+ vcom_epoll_t *vepoll;
+
+ p = hash_get (vsm->epollidx_by_epfd, epfd);
+ if (!p)
+ return -EBADF;
+
+ vepoll = pool_elt_at_index (vsm->vepolls, p[0]);
+ if (!vepoll)
+ return -EBADF;
+
+ if (vepoll->type != EPOLL_TYPE_VPPCOM_BOUND)
+ return -EINVAL;
+
+ if (vepoll->count)
+ {
+ if (!vepoll->close)
+ {
+ vepoll->close = 1;
+ return 0;
+ }
+ else
+ {
+ return -EBADF;
+ }
+ }
+
+ /* count is zero */
+ rv = vppcom_session_close (vepoll->vep_idx);
+ rv = vcom_socket_close_epoll (vepoll->epfd);
+
+ vepoll_init (vepoll);
+ hash_unset (vsm->epollidx_by_epfd, epfd);
+ pool_put (vsm->vepolls, vepoll);
+
+ return rv;
+}
+
+int
+vcom_socket_close (int __fd)
+{
+ int rv;
+
+ if (vcom_socket_is_vcom_fd (__fd))
+ {
+ rv = vcom_socket_close_vsock (__fd);
+ }
+ else if (vcom_socket_is_vcom_epfd (__fd))
+ {
+ rv = vcom_socket_close_vepoll (__fd);
+ }
+ else
+ {
+ rv = -EBADF;
+ }
+
return rv;
}
@@ -288,9 +499,9 @@ vcom_socket_read (int __fd, void *__buf, size_t __nbytes)
if (!(rv & O_NONBLOCK))
{
do
- {
- rv = vppcom_session_read (vsock->sid, __buf, __nbytes);
- }
+ {
+ rv = vppcom_session_read (vsock->sid, __buf, __nbytes);
+ }
while (rv == -EAGAIN || rv == -EWOULDBLOCK);
return rv;
}
@@ -433,16 +644,16 @@ vcom_socket_fcntl_va (int __fd, int __cmd, va_list __ap)
static inline int
vcom_socket_fds_2_sid_fds (
- /* dest */
- int *vcom_nsid_fds,
- fd_set * __restrict vcom_rd_sid_fds,
- fd_set * __restrict vcom_wr_sid_fds,
- fd_set * __restrict vcom_ex_sid_fds,
- /* src */
- int vcom_nfds,
- fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds)
+ /* dest */
+ int *vcom_nsid_fds,
+ fd_set * __restrict vcom_rd_sid_fds,
+ fd_set * __restrict vcom_wr_sid_fds,
+ fd_set * __restrict vcom_ex_sid_fds,
+ /* src */
+ int vcom_nfds,
+ fd_set * __restrict vcom_readfds,
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds)
{
int rv = 0;
int fd;
@@ -507,17 +718,17 @@ done:
*/
static inline int
vcom_socket_sid_fds_2_fds (
- /* dest */
- int *new_vcom_nfds,
- int vcom_nfds,
- fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds,
- /* src */
- int vcom_nsid_fds,
- fd_set * __restrict vcom_rd_sid_fds,
- fd_set * __restrict vcom_wr_sid_fds,
- fd_set * __restrict vcom_ex_sid_fds)
+ /* dest */
+ int *new_vcom_nfds,
+ int vcom_nfds,
+ fd_set * __restrict vcom_readfds,
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds,
+ /* src */
+ int vcom_nsid_fds,
+ fd_set * __restrict vcom_rd_sid_fds,
+ fd_set * __restrict vcom_wr_sid_fds,
+ fd_set * __restrict vcom_ex_sid_fds)
{
int rv = 0;
int fd;
@@ -604,9 +815,9 @@ done:
*/
int
vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds,
- struct timeval *__restrict timeout)
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds,
+ struct timeval *__restrict timeout)
{
int rv = -EBADF;
pid_t pid = getpid ();
@@ -634,17 +845,17 @@ vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
if (timeout)
{
if (timeout->tv_sec == 0 && timeout->tv_usec == 0)
- {
- /* polling: vppcom_select returns immediately */
- time_to_wait = (double) 0;
- }
+ {
+ /* polling: vppcom_select returns immediately */
+ time_to_wait = (double) 0;
+ }
else
- {
- /*TBD: use timeval api */
- time_to_wait = (double) timeout->tv_sec +
- (double) timeout->tv_usec / (double) 1000000 +
- (double) (timeout->tv_usec % 1000000) / (double) 1000000;
- }
+ {
+ /*TBD: use timeval api */
+ time_to_wait = (double) timeout->tv_sec +
+ (double) timeout->tv_usec / (double) 1000000 +
+ (double) (timeout->tv_usec % 1000000) / (double) 1000000;
+ }
}
else
{
@@ -675,20 +886,20 @@ vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
/* populate read, write and except sid_sets */
vcom_nsid = vcom_socket_fds_2_sid_fds (
- /* dest */
- vcom_readfds || vcom_writefds
- || vcom_exceptfds ? (int *)
- &vcom_nsid_fds : NULL,
- vcom_readfds ? &vcom_rd_sid_fds :
- NULL,
- vcom_writefds ? &vcom_wr_sid_fds :
- NULL,
- vcom_exceptfds ? &vcom_ex_sid_fds :
- NULL,
- /* src */
- vcom_nfds,
- vcom_readfds,
- vcom_writefds, vcom_exceptfds);
+ /* dest */
+ vcom_readfds || vcom_writefds
+ || vcom_exceptfds ? (int *)
+ &vcom_nsid_fds : NULL,
+ vcom_readfds ? &vcom_rd_sid_fds :
+ NULL,
+ vcom_writefds ? &vcom_wr_sid_fds :
+ NULL,
+ vcom_exceptfds ? &vcom_ex_sid_fds :
+ NULL,
+ /* src */
+ vcom_nfds,
+ vcom_readfds,
+ vcom_writefds, vcom_exceptfds);
if (vcom_nsid < 0)
{
return vcom_nsid;
@@ -699,15 +910,15 @@ vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
}
rv = vppcom_select (vcom_nsid_fds,
- vcom_readfds ? (unsigned long *) &vcom_rd_sid_fds :
- NULL,
- vcom_writefds ? (unsigned long *) &vcom_wr_sid_fds :
- NULL,
- vcom_exceptfds ? (unsigned long *) &vcom_ex_sid_fds :
- NULL, time_to_wait);
+ vcom_readfds ? (unsigned long *) &vcom_rd_sid_fds :
+ NULL,
+ vcom_writefds ? (unsigned long *) &vcom_wr_sid_fds :
+ NULL,
+ vcom_exceptfds ? (unsigned long *) &vcom_ex_sid_fds :
+ NULL, time_to_wait);
if (VCOM_DEBUG > 0)
fprintf (stderr, "[%d] vppcom_select: "
- "'%04d'='%04d'\n", pid, rv, (int) vcom_nsid_fds);
+ "'%04d'='%04d'\n", pid, rv, (int) vcom_nsid_fds);
/* check if any file descriptors changed status */
if (rv > 0)
@@ -723,28 +934,28 @@ vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
* vcom_socket_sid_fds_2_fds
*/
new_vcom_nfd = vcom_socket_sid_fds_2_fds (
- /* dest */
- &new_vcom_nfds,
- vcom_nfds,
- vcom_readfds,
- vcom_writefds,
- vcom_exceptfds,
- /* src */
- vcom_nsid_fds,
- vcom_readfds ?
- &vcom_rd_sid_fds : NULL,
- vcom_writefds ?
- &vcom_wr_sid_fds : NULL,
- vcom_exceptfds ?
- &vcom_ex_sid_fds : NULL);
+ /* dest */
+ &new_vcom_nfds,
+ vcom_nfds,
+ vcom_readfds,
+ vcom_writefds,
+ vcom_exceptfds,
+ /* src */
+ vcom_nsid_fds,
+ vcom_readfds ?
+ &vcom_rd_sid_fds : NULL,
+ vcom_writefds ?
+ &vcom_wr_sid_fds : NULL,
+ vcom_exceptfds ?
+ &vcom_ex_sid_fds : NULL);
if (new_vcom_nfd < 0)
- {
- return new_vcom_nfd;
- }
+ {
+ return new_vcom_nfd;
+ }
if (new_vcom_nfds < 0)
- {
- return -EINVAL;
- }
+ {
+ return -EINVAL;
+ }
rv = new_vcom_nfd;
}
return rv;
@@ -772,9 +983,9 @@ vcom_socket_socket (int __domain, int __type, int __protocol)
}
sid = vppcom_session_create (VPPCOM_VRF_DEFAULT,
- (type == SOCK_DGRAM) ?
- VPPCOM_PROTO_UDP : VPPCOM_PROTO_TCP,
- is_nonblocking);
+ (type == SOCK_DGRAM) ?
+ VPPCOM_PROTO_UDP : VPPCOM_PROTO_TCP,
+ is_nonblocking);
if (sid < 0)
{
rv = sid;
@@ -782,6 +993,8 @@ vcom_socket_socket (int __domain, int __type, int __protocol)
}
pool_get (vsm->vsockets, vsock);
+ vsocket_init (vsock);
+
sockidx = vsock - vsm->vsockets;
hash_set (vsm->sockidx_by_fd, fd, sockidx);
@@ -796,7 +1009,7 @@ out:
int
vcom_socket_socketpair (int __domain, int __type, int __protocol,
- int __fds[2])
+ int __fds[2])
{
/* TBD: */
return 0;
@@ -833,9 +1046,9 @@ vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
{
case AF_INET:
if (__len != sizeof (struct sockaddr_in))
- {
- return -EINVAL;
- }
+ {
+ return -EINVAL;
+ }
ep.is_ip4 = VPPCOM_IS_IP4;
ep.ip = (u8 *) & ((const struct sockaddr_in *) __addr)->sin_addr;
ep.port = (u16) ((const struct sockaddr_in *) __addr)->sin_port;
@@ -843,9 +1056,9 @@ vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
case AF_INET6:
if (__len != sizeof (struct sockaddr_in6))
- {
- return -EINVAL;
- }
+ {
+ return -EINVAL;
+ }
ep.is_ip4 = VPPCOM_IS_IP6;
ep.ip = (u8 *) & ((const struct sockaddr_in6 *) __addr)->sin6_addr;
ep.port = (u16) ((const struct sockaddr_in6 *) __addr)->sin6_port;
@@ -863,9 +1076,9 @@ vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
{
rv = libc_bind (__fd, __addr, __len);
if (rv != 0)
- {
- rv = -errno;
- }
+ {
+ rv = -errno;
+ }
}
return rv;
}
@@ -879,7 +1092,7 @@ vppcom_session_getsockname (int sid, vppcom_endpt_t * ep)
int
vcom_socket_getsockname (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len)
+ socklen_t * __restrict __len)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -924,24 +1137,24 @@ vcom_socket_getsockname (int __fd, __SOCKADDR_ARG __addr,
if (rv == 0)
{
if (ep.vrf == VPPCOM_VRF_DEFAULT)
- {
- __addr->sa_family = ep.is_ip4 == VPPCOM_IS_IP4 ? AF_INET : AF_INET6;
- switch (__addr->sa_family)
- {
- case AF_INET:
- ((struct sockaddr_in *) __addr)->sin_port = ep.port;
- *__len = sizeof (struct sockaddr_in);
- break;
-
- case AF_INET6:
- ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
- *__len = sizeof (struct sockaddr_in6);
- break;
-
- default:
- break;
- }
- }
+ {
+ __addr->sa_family = ep.is_ip4 == VPPCOM_IS_IP4 ? AF_INET : AF_INET6;
+ switch (__addr->sa_family)
+ {
+ case AF_INET:
+ ((struct sockaddr_in *) __addr)->sin_port = ep.port;
+ *__len = sizeof (struct sockaddr_in);
+ break;
+
+ case AF_INET6:
+ ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
+ *__len = sizeof (struct sockaddr_in6);
+ break;
+
+ default:
+ break;
+ }
+ }
}
#endif
@@ -965,27 +1178,27 @@ vcom_socket_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
ep.vrf = VPPCOM_VRF_DEFAULT;
switch (__addr->sa_family)
- {
- case AF_INET:
- ep.is_ip4 = VPPCOM_IS_IP4;
- ep.ip =
- (uint8_t *) & ((const struct sockaddr_in *) __addr)->sin_addr;
- ep.port =
- (uint16_t) ((const struct sockaddr_in *) __addr)->sin_port;
- break;
-
- case AF_INET6:
- ep.is_ip4 = VPPCOM_IS_IP6;
- ep.ip =
- (uint8_t *) & ((const struct sockaddr_in6 *) __addr)->sin6_addr;
- ep.port =
- (uint16_t) ((const struct sockaddr_in6 *) __addr)->sin6_port;
- break;
-
- default:
- return -1;
- break;
- }
+ {
+ case AF_INET:
+ ep.is_ip4 = VPPCOM_IS_IP4;
+ ep.ip =
+ (uint8_t *) & ((const struct sockaddr_in *) __addr)->sin_addr;
+ ep.port =
+ (uint16_t) ((const struct sockaddr_in *) __addr)->sin_port;
+ break;
+
+ case AF_INET6:
+ ep.is_ip4 = VPPCOM_IS_IP6;
+ ep.ip =
+ (uint8_t *) & ((const struct sockaddr_in6 *) __addr)->sin6_addr;
+ ep.port =
+ (uint16_t) ((const struct sockaddr_in6 *) __addr)->sin6_port;
+ break;
+
+ default:
+ return -1;
+ break;
+ }
rv = vppcom_session_connect (vsock->sid, &ep);
}
@@ -1001,7 +1214,7 @@ vppcom_session_getpeername (int sid, vppcom_endpt_t * ep)
int
vcom_socket_getpeername (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len)
+ socklen_t * __restrict __len)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1060,24 +1273,24 @@ vcom_socket_getpeername (int __fd, __SOCKADDR_ARG __addr,
if (rv == 0)
{
if (ep.vrf == VPPCOM_VRF_DEFAULT)
- {
- __addr->sa_family = ep.is_ip4 == VPPCOM_IS_IP4 ? AF_INET : AF_INET6;
- switch (__addr->sa_family)
- {
- case AF_INET:
- ((struct sockaddr_in *) __addr)->sin_port = ep.port;
- *__len = sizeof (struct sockaddr_in);
- break;
-
- case AF_INET6:
- ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
- *__len = sizeof (struct sockaddr_in6);
- break;
-
- default:
- break;
- }
- }
+ {
+ __addr->sa_family = ep.is_ip4 == VPPCOM_IS_IP4 ? AF_INET : AF_INET6;
+ switch (__addr->sa_family)
+ {
+ case AF_INET:
+ ((struct sockaddr_in *) __addr)->sin_port = ep.port;
+ *__len = sizeof (struct sockaddr_in);
+ break;
+
+ case AF_INET6:
+ ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
+ *__len = sizeof (struct sockaddr_in6);
+ break;
+
+ default:
+ break;
+ }
+ }
}
#endif
@@ -1120,34 +1333,34 @@ vcom_socket_is_connection_mode_socket (int __fd)
{
vsock = pool_elt_at_index (vsm->vsockets, p[0]);
if (vsock && vsock->type == SOCKET_TYPE_VPPCOM_BOUND)
- {
- optlen = sizeof (type);
- rv = libc_getsockopt (__fd, SOL_SOCKET, SO_TYPE, &type, &optlen);
- if (rv != 0)
- {
- return 0;
- }
- /* get socket type */
- switch (type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
- {
- case SOCK_STREAM:
- case SOCK_SEQPACKET:
- return 1;
- break;
-
- default:
- return 0;
- break;
- }
- }
+ {
+ optlen = sizeof (type);
+ rv = libc_getsockopt (__fd, SOL_SOCKET, SO_TYPE, &type, &optlen);
+ if (rv != 0)
+ {
+ return 0;
+ }
+ /* get socket type */
+ switch (type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
+ {
+ case SOCK_STREAM:
+ case SOCK_SEQPACKET:
+ return 1;
+ break;
+
+ default:
+ return 0;
+ break;
+ }
+ }
}
return 0;
}
ssize_t
vvppcom_session_sendto (int __sid, const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr,
- socklen_t __addr_len)
+ int __flags, __CONST_SOCKADDR_ARG __addr,
+ socklen_t __addr_len)
{
int rv = -1;
/* TBD add new vpp api */
@@ -1158,8 +1371,8 @@ vvppcom_session_sendto (int __sid, const void *__buf, size_t __n,
ssize_t
vcom_socket_sendto (int __fd, const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr,
- socklen_t __addr_len)
+ int __flags, __CONST_SOCKADDR_ARG __addr,
+ socklen_t __addr_len)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1187,33 +1400,33 @@ vcom_socket_sendto (int __fd, const void *__buf, size_t __n,
/* ignore __addr and _addr_len */
/* and EISCONN may be returned when they are not NULL and 0 */
if ((__addr != NULL) || (__addr_len != 0))
- {
- return -EISCONN;
- }
+ {
+ return -EISCONN;
+ }
}
else
{
if (!__addr || __addr_len < 0)
- {
- return -EDESTADDRREQ;
- }
+ {
+ return -EDESTADDRREQ;
+ }
/* not a vppcom supported address family */
if ((__addr->sa_family != AF_INET) || (__addr->sa_family != AF_INET6))
- {
- return -EINVAL;
- }
+ {
+ return -EINVAL;
+ }
}
rv = vvppcom_session_sendto (vsock->sid, (void *) __buf, (int) __n,
- __flags, __addr, __addr_len);
+ __flags, __addr, __addr_len);
return rv;
}
/* TBD: move it to vppcom */
static ssize_t
vppcom_session_recvfrom (int __sid, void *__restrict __buf, size_t __n,
- int __flags, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len)
+ int __flags, __SOCKADDR_ARG __addr,
+ socklen_t * __restrict __addr_len)
{
int rv = -1;
@@ -1224,8 +1437,8 @@ vppcom_session_recvfrom (int __sid, void *__restrict __buf, size_t __n,
ssize_t
vcom_socket_recvfrom (int __fd, void *__restrict __buf, size_t __n,
- int __flags, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len)
+ int __flags, __SOCKADDR_ARG __addr,
+ socklen_t * __restrict __addr_len)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1254,7 +1467,7 @@ vcom_socket_recvfrom (int __fd, void *__restrict __buf, size_t __n,
}
rv = vppcom_session_recvfrom (vsock->sid, __buf, __n,
- __flags, __addr, __addr_len);
+ __flags, __addr, __addr_len);
return rv;
}
@@ -1289,9 +1502,9 @@ vcom_socket_sendmsg (int __fd, const struct msghdr * __message, int __flags)
/* ignore __addr and _addr_len */
/* and EISCONN may be returned when they are not NULL and 0 */
if ((__message->msg_name != NULL) || (__message->msg_namelen != 0))
- {
- return -EISCONN;
- }
+ {
+ return -EISCONN;
+ }
}
else
{
@@ -1309,7 +1522,7 @@ vcom_socket_sendmsg (int __fd, const struct msghdr * __message, int __flags)
#ifdef __USE_GNU
int
vcom_socket_sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags)
+ unsigned int __vlen, int __flags)
{
/* TBD: define a new vppcom api */
@@ -1360,8 +1573,8 @@ vcom_socket_recvmsg (int __fd, struct msghdr * __message, int __flags)
#ifdef __USE_GNU
int
vcom_socket_recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags,
- struct timespec *__tmo)
+ unsigned int __vlen, int __flags,
+ struct timespec *__tmo)
{
/* TBD: define a new vppcom api */
return 0;
@@ -1371,7 +1584,7 @@ vcom_socket_recvmmsg (int __fd, struct mmsghdr *__vmessages,
/* TBD: move it to vppcom */
static int
vppcom_getsockopt (int __sid, int __level, int __optname,
- void *__restrict __optval, socklen_t * __restrict __optlen)
+ void *__restrict __optval, socklen_t * __restrict __optlen)
{
/* 1. for socket level options that are NOT socket attributes
* and that has corresponding vpp options get from vppcom */
@@ -1385,8 +1598,8 @@ vppcom_getsockopt (int __sid, int __level, int __optname,
int
vcom_socket_getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval,
- socklen_t * __restrict __optlen)
+ void *__restrict __optval,
+ socklen_t * __restrict __optlen)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1417,7 +1630,7 @@ vcom_socket_getsockopt (int __fd, int __level, int __optname,
/* handle options at socket level */
case SOL_SOCKET:
switch (__optname)
- {
+ {
/*
* 1. for socket level options that are socket attributes,
* get from libc_getsockopt.
@@ -1426,65 +1639,65 @@ vcom_socket_getsockopt (int __fd, int __level, int __optname,
* get from vppcom.
* 3. for socket level options unimplemented
* return -ENOPROTOOPT */
- case SO_DEBUG:
- case SO_DONTROUTE:
- case SO_BROADCAST:
- case SO_SNDBUF:
- case SO_RCVBUF:
- case SO_REUSEADDR:
- case SO_REUSEPORT:
- case SO_KEEPALIVE:
- case SO_TYPE:
- case SO_PROTOCOL:
- case SO_DOMAIN:
- case SO_ERROR:
- case SO_OOBINLINE:
- case SO_NO_CHECK:
- case SO_PRIORITY:
- case SO_LINGER:
- case SO_BSDCOMPAT:
- case SO_TIMESTAMP:
- case SO_TIMESTAMPNS:
- case SO_TIMESTAMPING:
- case SO_RCVTIMEO:
- case SO_SNDTIMEO:
- case SO_RCVLOWAT:
- case SO_SNDLOWAT:
- case SO_PASSCRED:
- case SO_PEERCRED:
- case SO_PEERNAME:
- case SO_ACCEPTCONN:
- case SO_PASSSEC:
- case SO_PEERSEC:
- case SO_MARK:
- case SO_RXQ_OVFL:
- case SO_WIFI_STATUS:
- case SO_PEEK_OFF:
- case SO_NOFCS:
- case SO_BINDTODEVICE:
- case SO_GET_FILTER:
- case SO_LOCK_FILTER:
- case SO_BPF_EXTENSIONS:
- case SO_SELECT_ERR_QUEUE:
+ case SO_DEBUG:
+ case SO_DONTROUTE:
+ case SO_BROADCAST:
+ case SO_SNDBUF:
+ case SO_RCVBUF:
+ case SO_REUSEADDR:
+ case SO_REUSEPORT:
+ case SO_KEEPALIVE:
+ case SO_TYPE:
+ case SO_PROTOCOL:
+ case SO_DOMAIN:
+ case SO_ERROR:
+ case SO_OOBINLINE:
+ case SO_NO_CHECK:
+ case SO_PRIORITY:
+ case SO_LINGER:
+ case SO_BSDCOMPAT:
+ case SO_TIMESTAMP:
+ case SO_TIMESTAMPNS:
+ case SO_TIMESTAMPING:
+ case SO_RCVTIMEO:
+ case SO_SNDTIMEO:
+ case SO_RCVLOWAT:
+ case SO_SNDLOWAT:
+ case SO_PASSCRED:
+ case SO_PEERCRED:
+ case SO_PEERNAME:
+ case SO_ACCEPTCONN:
+ case SO_PASSSEC:
+ case SO_PEERSEC:
+ case SO_MARK:
+ case SO_RXQ_OVFL:
+ case SO_WIFI_STATUS:
+ case SO_PEEK_OFF:
+ case SO_NOFCS:
+ case SO_BINDTODEVICE:
+ case SO_GET_FILTER:
+ case SO_LOCK_FILTER:
+ case SO_BPF_EXTENSIONS:
+ case SO_SELECT_ERR_QUEUE:
#ifdef CONFIG_NET_RX_BUSY_POLL
- case SO_BUSY_POLL:
+ case SO_BUSY_POLL:
#endif
- case SO_MAX_PACING_RATE:
- case SO_INCOMING_CPU:
- rv = libc_getsockopt (__fd, __level, __optname, __optval, __optlen);
- if (rv != 0)
- {
- rv = -errno;
- return rv;
- }
- break;
-
- default:
- /* We implement the SO_SNDLOWAT etc to not be settable
- * (1003.1g 7).
- */
- return -ENOPROTOOPT;
- }
+ case SO_MAX_PACING_RATE:
+ case SO_INCOMING_CPU:
+ rv = libc_getsockopt (__fd, __level, __optname, __optval, __optlen);
+ if (rv != 0)
+ {
+ rv = -errno;
+ return rv;
+ }
+ break;
+
+ default:
+ /* We implement the SO_SNDLOWAT etc to not be settable
+ * (1003.1g 7).
+ */
+ return -ENOPROTOOPT;
+ }
break;
@@ -1492,7 +1705,7 @@ vcom_socket_getsockopt (int __fd, int __level, int __optname,
/* 1. handle options that are NOT socket level options,
* but have corresponding vpp otions. */
rv = vppcom_getsockopt (vsock->sid, __level, __optname,
- __optval, __optlen);
+ __optval, __optlen);
return rv;
#if 0
@@ -1507,7 +1720,7 @@ vcom_socket_getsockopt (int __fd, int __level, int __optname,
/* TBD: move it to vppcom */
int
vppcom_setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen)
+ const void *__optval, socklen_t __optlen)
{
/* 1. for socket level options that are NOT socket attributes
* and that has corresponding vpp options set it from vppcom */
@@ -1521,7 +1734,7 @@ vppcom_setsockopt (int __fd, int __level, int __optname,
int
vcom_socket_setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen)
+ const void *__optval, socklen_t __optlen)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1547,9 +1760,9 @@ vcom_socket_setsockopt (int __fd, int __level, int __optname,
{
rv = libc_setsockopt (__fd, __level, __optname, __optval, __optlen);
if (rv != 0)
- {
- rv = -errno;
- }
+ {
+ rv = -errno;
+ }
return rv;
}
@@ -1564,77 +1777,77 @@ vcom_socket_setsockopt (int __fd, int __level, int __optname,
/* handle options at socket level */
case SOL_SOCKET:
switch (__optname)
- {
- /*
- * 1. for socket level options that are socket attributes,
- * set it from libc_getsockopt
- * 2. for socket level options that are NOT socket
- * attributes and that has corresponding vpp options
- * set it from vppcom
- * 3. for socket level options unimplemented
- * return -ENOPROTOOPT */
- case SO_DEBUG:
- case SO_DONTROUTE:
- case SO_BROADCAST:
- case SO_SNDBUF:
- case SO_RCVBUF:
- case SO_REUSEADDR:
- case SO_REUSEPORT:
- case SO_KEEPALIVE:
- case SO_TYPE:
- case SO_PROTOCOL:
- case SO_DOMAIN:
- case SO_ERROR:
- case SO_OOBINLINE:
- case SO_NO_CHECK:
- case SO_PRIORITY:
- case SO_LINGER:
- case SO_BSDCOMPAT:
- case SO_TIMESTAMP:
- case SO_TIMESTAMPNS:
- case SO_TIMESTAMPING:
- case SO_RCVTIMEO:
- case SO_SNDTIMEO:
- case SO_RCVLOWAT:
- case SO_SNDLOWAT:
- case SO_PASSCRED:
- case SO_PEERCRED:
- case SO_PEERNAME:
- case SO_ACCEPTCONN:
- case SO_PASSSEC:
- case SO_PEERSEC:
- case SO_MARK:
- case SO_RXQ_OVFL:
- case SO_WIFI_STATUS:
- case SO_PEEK_OFF:
- case SO_NOFCS:
- /*
- * SO_BINDTODEVICE already handled as
- * "Options without arguments" */
- /* case SO_BINDTODEVICE: */
- case SO_GET_FILTER:
- case SO_LOCK_FILTER:
- case SO_BPF_EXTENSIONS:
- case SO_SELECT_ERR_QUEUE:
+ {
+ /*
+ * 1. for socket level options that are socket attributes,
+ * set it from libc_getsockopt
+ * 2. for socket level options that are NOT socket
+ * attributes and that has corresponding vpp options
+ * set it from vppcom
+ * 3. for socket level options unimplemented
+ * return -ENOPROTOOPT */
+ case SO_DEBUG:
+ case SO_DONTROUTE:
+ case SO_BROADCAST:
+ case SO_SNDBUF:
+ case SO_RCVBUF:
+ case SO_REUSEADDR:
+ case SO_REUSEPORT:
+ case SO_KEEPALIVE:
+ case SO_TYPE:
+ case SO_PROTOCOL:
+ case SO_DOMAIN:
+ case SO_ERROR:
+ case SO_OOBINLINE:
+ case SO_NO_CHECK:
+ case SO_PRIORITY:
+ case SO_LINGER:
+ case SO_BSDCOMPAT:
+ case SO_TIMESTAMP:
+ case SO_TIMESTAMPNS:
+ case SO_TIMESTAMPING:
+ case SO_RCVTIMEO:
+ case SO_SNDTIMEO:
+ case SO_RCVLOWAT:
+ case SO_SNDLOWAT:
+ case SO_PASSCRED:
+ case SO_PEERCRED:
+ case SO_PEERNAME:
+ case SO_ACCEPTCONN:
+ case SO_PASSSEC:
+ case SO_PEERSEC:
+ case SO_MARK:
+ case SO_RXQ_OVFL:
+ case SO_WIFI_STATUS:
+ case SO_PEEK_OFF:
+ case SO_NOFCS:
+ /*
+ * SO_BINDTODEVICE already handled as
+ * "Options without arguments" */
+ /* case SO_BINDTODEVICE: */
+ case SO_GET_FILTER:
+ case SO_LOCK_FILTER:
+ case SO_BPF_EXTENSIONS:
+ case SO_SELECT_ERR_QUEUE:
#ifdef CONFIG_NET_RX_BUSY_POLL
- case SO_BUSY_POLL:
+ case SO_BUSY_POLL:
#endif
- case SO_MAX_PACING_RATE:
- case SO_INCOMING_CPU:
- rv = libc_setsockopt (__fd, __level, __optname, __optval, __optlen);
- if (rv != 0)
- {
- rv = -errno;
- return rv;
- }
- break;
-
- default:
- /* We implement the SO_SNDLOWAT etc to not be settable
- * (1003.1g 7).
- */
- return -ENOPROTOOPT;
- }
+ case SO_MAX_PACING_RATE:
+ case SO_INCOMING_CPU:
+ rv = libc_setsockopt (__fd, __level, __optname, __optval, __optlen);
+ if (rv != 0)
+ {
+ rv = -errno;
+ return rv;
+ }
+ break;
+
+ default:
+ /* We implement the SO_SNDLOWAT etc to not be settable
+ * (1003.1g 7).
+ */
+ return -ENOPROTOOPT;
+ }
break;
@@ -1642,7 +1855,7 @@ vcom_socket_setsockopt (int __fd, int __level, int __optname,
/* 1. handle options that are NOT socket level options,
* but have corresponding vpp otions. */
rv = vppcom_setsockopt (vsock->sid, __level, __optname,
- __optval, __optlen);
+ __optval, __optlen);
return rv;
#if 0
/* 2. unhandled options */
@@ -1675,8 +1888,8 @@ vcom_socket_listen (int __fd, int __n)
static int
vcom_socket_connected_socket (int __fd, int __sid,
- int *__domain,
- int *__type, int *__protocol, int flags)
+ int *__domain,
+ int *__type, int *__protocol, int flags)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1719,6 +1932,8 @@ vcom_socket_connected_socket (int __fd, int __sid,
}
pool_get (vsm->vsockets, vsock);
+ vsocket_init (vsock);
+
sockidx = vsock - vsm->vsockets;
hash_set (vsm->sockidx_by_fd, fd, sockidx);
@@ -1734,7 +1949,7 @@ out:
*/
static int
vcom_socket_accept_flags (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int flags)
+ socklen_t * __restrict __addr_len, int flags)
{
int rv = -1;
vcom_socket_main_t *vsm = &vcom_socket_main;
@@ -1792,43 +2007,43 @@ vcom_socket_accept_flags (int __fd, __SOCKADDR_ARG __addr,
rv = vcom_fcntl (vsock->fd, F_GETFL, 0);
if (rv < 0)
- {
- return rv;
- }
+ {
+ return rv;
+ }
/* is blocking */
if (!(rv & O_NONBLOCK))
- {
- /* socket is not marked as nonblocking
- * and no pending connections are present
- * on the queue, accept () blocks the caller
- * until a connection is present.
- */
- rv = vppcom_session_accept (vsock->sid, &ep,
- -1.0 /* wait forever */ );
- }
+ {
+ /* socket is not marked as nonblocking
+ * and no pending connections are present
+ * on the queue, accept () blocks the caller
+ * until a connection is present.
+ */
+ rv = vppcom_session_accept (vsock->sid, &ep,
+ -1.0 /* wait forever */ );
+ }
else
- {
- /* The file descriptor refers to a socket and has been
- * marked nonblocking(O_NONBLOCK) and the accept would
- * block.
- * */
- /* is non blocking */
- rv = vppcom_session_accept (vsock->sid, &ep, 0);
- /* If the socket is marked nonblocking and
- * no pending connections are present on the
- * queue, accept fails with the error
- * EAGAIN or EWOULDBLOCK
- */
- if (rv == VPPCOM_ETIMEDOUT)
- {
- rv = VPPCOM_EAGAIN;
- }
- }
+ {
+ /* The file descriptor refers to a socket and has been
+ * marked nonblocking(O_NONBLOCK) and the accept would
+ * block.
+ * */
+ /* is non blocking */
+ rv = vppcom_session_accept (vsock->sid, &ep, 0);
+ /* If the socket is marked nonblocking and
+ * no pending connections are present on the
+ * queue, accept fails with the error
+ * EAGAIN or EWOULDBLOCK
+ */
+ if (rv == VPPCOM_ETIMEDOUT)
+ {
+ rv = VPPCOM_EAGAIN;
+ }
+ }
if (rv < 0)
- {
- return rv;
- }
+ {
+ return rv;
+ }
sid = rv;
@@ -1837,11 +2052,11 @@ vcom_socket_accept_flags (int __fd, __SOCKADDR_ARG __addr,
* update vsockets and sockidx_by_fd table
* */
fd = vcom_socket_connected_socket (__fd, sid,
- &domain, &type, &protocol, flags);
+ &domain, &type, &protocol, flags);
if (fd < 0)
- {
- return fd;
- }
+ {
+ return fd;
+ }
rv = fd;
@@ -1850,87 +2065,87 @@ vcom_socket_accept_flags (int __fd, __SOCKADDR_ARG __addr,
* provided is too small, in this case, __addr_len will
* return a value greater than was supplied to the call.*/
if (__addr)
- {
- if (ep.is_cut_thru)
- {
- /* TBD populate __addr and __addr_len */
- switch (domain)
- {
- case AF_INET:
- ((struct sockaddr_in *) __addr)->sin_family = AF_INET;
- ((struct sockaddr_in *) __addr)->sin_port = ep.port;
- memcpy (&((struct sockaddr_in *) __addr)->sin_addr,
- addr8, sizeof (struct in_addr));
- /* TBD: populate __addr_len */
- if (__addr_len)
- {
- *__addr_len = sizeof (struct sockaddr_in);
- }
- break;
-
- case AF_INET6:
- ((struct sockaddr_in6 *) __addr)->sin6_family = AF_INET6;
- ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
- memcpy (((struct sockaddr_in6 *) __addr)->sin6_addr.
- __in6_u.__u6_addr8, addr8,
- sizeof (struct in6_addr));
- /* TBD: populate __addr_len */
- if (__addr_len)
- {
- *__addr_len = sizeof (struct sockaddr_in6);
- }
- break;
-
- default:
- return -EAFNOSUPPORT;
- }
- }
- else
- {
- switch (ep.is_ip4)
- {
- case VPPCOM_IS_IP4:
- ((struct sockaddr_in *) __addr)->sin_family = AF_INET;
- ((struct sockaddr_in *) __addr)->sin_port = ep.port;
- memcpy (&((struct sockaddr_in *) __addr)->sin_addr,
- addr8, sizeof (struct in_addr));
- /* TBD: populate __addr_len */
- if (__addr_len)
- {
- *__addr_len = sizeof (struct sockaddr_in);
- }
- break;
-
- case VPPCOM_IS_IP6:
- ((struct sockaddr_in6 *) __addr)->sin6_family = AF_INET6;
- ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
- memcpy (((struct sockaddr_in6 *) __addr)->sin6_addr.
- __in6_u.__u6_addr8, addr8,
- sizeof (struct in6_addr));
- /* TBD: populate __addr_len */
- if (__addr_len)
- {
- *__addr_len = sizeof (struct sockaddr_in6);
- }
- break;
-
- default:
- return -EAFNOSUPPORT;
- }
- }
- }
+ {
+ if (ep.is_cut_thru)
+ {
+ /* TBD populate __addr and __addr_len */
+ switch (domain)
+ {
+ case AF_INET:
+ ((struct sockaddr_in *) __addr)->sin_family = AF_INET;
+ ((struct sockaddr_in *) __addr)->sin_port = ep.port;
+ memcpy (&((struct sockaddr_in *) __addr)->sin_addr,
+ addr8, sizeof (struct in_addr));
+ /* TBD: populate __addr_len */
+ if (__addr_len)
+ {
+ *__addr_len = sizeof (struct sockaddr_in);
+ }
+ break;
+
+ case AF_INET6:
+ ((struct sockaddr_in6 *) __addr)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
+ memcpy (((struct sockaddr_in6 *) __addr)->sin6_addr.
+ __in6_u.__u6_addr8, addr8,
+ sizeof (struct in6_addr));
+ /* TBD: populate __addr_len */
+ if (__addr_len)
+ {
+ *__addr_len = sizeof (struct sockaddr_in6);
+ }
+ break;
+
+ default:
+ return -EAFNOSUPPORT;
+ }
+ }
+ else
+ {
+ switch (ep.is_ip4)
+ {
+ case VPPCOM_IS_IP4:
+ ((struct sockaddr_in *) __addr)->sin_family = AF_INET;
+ ((struct sockaddr_in *) __addr)->sin_port = ep.port;
+ memcpy (&((struct sockaddr_in *) __addr)->sin_addr,
+ addr8, sizeof (struct in_addr));
+ /* TBD: populate __addr_len */
+ if (__addr_len)
+ {
+ *__addr_len = sizeof (struct sockaddr_in);
+ }
+ break;
+
+ case VPPCOM_IS_IP6:
+ ((struct sockaddr_in6 *) __addr)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *) __addr)->sin6_port = ep.port;
+ memcpy (((struct sockaddr_in6 *) __addr)->sin6_addr.
+ __in6_u.__u6_addr8, addr8,
+ sizeof (struct in6_addr));
+ /* TBD: populate __addr_len */
+ if (__addr_len)
+ {
+ *__addr_len = sizeof (struct sockaddr_in6);
+ }
+ break;
+
+ default:
+ return -EAFNOSUPPORT;
+ }
+ }
+ }
else
- {
- /* when __addr is NULL, nothing is filled in,
- * in this case, __addr_len is not used,
- * and should also be null
- * */
- if (__addr_len)
- {
- /* TBD: return proper error code */
- return -1;
- }
- }
+ {
+ /* when __addr is NULL, nothing is filled in,
+ * in this case, __addr_len is not used,
+ * and should also be null
+ * */
+ if (__addr_len)
+ {
+ /* TBD: return proper error code */
+ return -1;
+ }
+ }
}
return rv;
@@ -1938,7 +2153,7 @@ vcom_socket_accept_flags (int __fd, __SOCKADDR_ARG __addr,
int
vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len)
+ socklen_t * __restrict __addr_len)
{
/* set flags to 0 for accept() */
return vcom_socket_accept_flags (__fd, __addr, __addr_len, 0);
@@ -1947,7 +2162,7 @@ vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
#ifdef __USE_GNU
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags)
+ socklen_t * __restrict __addr_len, int __flags)
{
/* SOCK_NONBLOCK and SOCK_CLOEXEC can be bitwise ORed in flags */
return vcom_socket_accept_flags (__fd, __addr, __addr_len, __flags);
@@ -1974,23 +2189,86 @@ vcom_socket_shutdown (int __fd, int __how)
{
vsock = pool_elt_at_index (vsm->vsockets, p[0]);
switch (__how)
- {
- case SHUT_RD:
- case SHUT_WR:
- case SHUT_RDWR:
- rv = vppcom_session_shutdown (vsock->sid, __how);
- return rv;
- break;
+ {
+ case SHUT_RD:
+ case SHUT_WR:
+ case SHUT_RDWR:
+ rv = vppcom_session_shutdown (vsock->sid, __how);
+ return rv;
+ break;
+
+ default:
+ return -EINVAL;
+ break;
+ }
+ }
- default:
- return -EINVAL;
- break;
- }
+ return rv;
+}
+
+/*
+ * TBD: remove it once vppvom.h is committed.
+ */
+int vppcom_epoll_create (void)
+{
+ return -ENOSYS;
+}
+int
+vcom_socket_epoll_create1 (int __flags)
+{
+ int rv = -1;
+ vcom_socket_main_t *vsm = &vcom_socket_main;
+ vcom_epoll_t *vepoll;
+
+ i32 epfd;
+ i32 vep_idx;
+ i32 epollidx;
+
+ epfd = vcom_socket_open_epoll (__flags);
+ if (epfd < 0)
+ {
+ rv = epfd;
+ goto out;
+ }
+
+ vep_idx = vppcom_epoll_create ( );
+ if (vep_idx < 0)
+ {
+ rv = vep_idx;
+ goto out_close_epoll;
}
+ pool_get (vsm->vepolls, vepoll);
+ vepoll_init (vepoll);
+
+ epollidx = vepoll - vsm->vepolls;
+ hash_set (vsm->epollidx_by_epfd, epfd, epollidx);
+
+ vepoll_set (vepoll, epfd, vep_idx,
+ EPOLL_TYPE_VPPCOM_BOUND, __flags, 0, 0);
+ return epfd;
+
+out_close_epoll:
+ vcom_socket_close_epoll (epfd);
+out:
return rv;
}
+int
+vcom_socket_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event)
+{
+ return -ENOSYS;
+}
+
+int
+vcom_socket_epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss)
+{
+ return -ENOSYS;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h
index b616002..903f740 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h
@@ -16,12 +16,17 @@
#ifndef included_vcom_socket_h
#define included_vcom_socket_h
+#include <string.h>
+
#include <libvcl-ldpreload/vcom_glibc_socket.h>
#include <vppinfra/types.h>
#define INVALID_SESSION_ID (~0)
#define INVALID_FD (~0)
+#define INVALID_VEP_IDX INVALID_SESSION_ID
+#define INVALID_EPFD INVALID_FD
+
typedef enum
{
SOCKET_TYPE_UNBOUND = 0,
@@ -29,6 +34,24 @@ typedef enum
SOCKET_TYPE_VPPCOM_BOUND
} vcom_socket_type_t;
+typedef enum
+{
+ EPOLL_TYPE_UNBOUND = 0,
+ EPOLL_TYPE_KERNEL_BOUND,
+ EPOLL_TYPE_VPPCOM_BOUND
+} vcom_epoll_type_t;
+
+typedef enum
+{
+ FD_TYPE_INVALID = 0,
+ FD_TYPE_KERNEL,
+ FD_TYPE_EPOLL,
+ FD_TYPE_VCOM_SOCKET,
+ /* add new types here */
+ /* FD_TYPE_MAX should be the last entry */
+ FD_TYPE_MAX
+} vcom_fd_type_t;
+
typedef struct
{
/* file descriptor -
@@ -46,6 +69,64 @@ typedef struct
} vcom_socket_t;
+typedef struct
+{
+ /* epoll file descriptor -
+ * epfd 0, 1, 2 have special meaning and are reserved,
+ * -1 denote invalid epfd */
+ i32 epfd;
+
+ /* vep idx - -1 denote invalid vep_idx */
+ i32 vep_idx;
+
+ /* epoll type */
+ vcom_epoll_type_t type;
+
+ /* flags - 0 or EPOLL_CLOEXEC */
+ i32 flags;
+
+ /* vcom epoll attributes here */
+
+ /*
+ * 00. count of file descriptors currently registered
+ * on this epoll instance.
+ * 01. number of file descriptors in the epoll set.
+ * 02. EPOLL_CTL_ADD, EPOLL_CTL_MOD, EPOLL_CTL_DEL
+ * update the count.
+ * 03. cached for frequent access.
+ * */
+ i32 count;
+
+ /* close( ) called on this epoll instance */
+ /* 0 - close ( ) not called, 1 - close( ) called. */
+ u32 close;
+
+} vcom_epoll_t;
+
+typedef struct
+{
+ /* "container" of this item */
+ i32 epfd;
+
+ /* fd - file descriptor information this item refers to */
+ i32 fd;
+ /* next and prev fd in the "epoll set" of epfd */
+ i32 next_fd;
+ i32 prev_fd;
+
+ /* vcom fd type */
+ vcom_fd_type_t type;
+
+ /* interested events and the source fd */
+ struct epoll_event event;
+
+ /* ready events and the source fd */
+ struct epoll_event revent;
+
+ /* epitem attributes here */
+
+} vcom_epitem_t;
+
static inline char *
vcom_socket_type_str (vcom_socket_type_t t)
{
@@ -65,15 +146,61 @@ vcom_socket_type_str (vcom_socket_type_t t)
}
}
+static inline char *
+vcom_socket_epoll_type_str (vcom_epoll_type_t t)
+{
+ switch (t)
+ {
+ case EPOLL_TYPE_UNBOUND:
+ return "EPOLL_TYPE_UNBOUND";
+
+ case EPOLL_TYPE_KERNEL_BOUND:
+ return "EPOLL_TYPE_KERNEL_BOUND";
+
+ case EPOLL_TYPE_VPPCOM_BOUND:
+ return "EPOLL_TYPE_VPPCOM_BOUND";
+
+ default:
+ return "EPOLL_TYPE_UNKNOWN";
+ }
+}
+
+static inline char *
+vcom_socket_vcom_fd_type_str (vcom_fd_type_t t)
+{
+ switch (t)
+ {
+ case FD_TYPE_KERNEL:
+ return "FD_TYPE_KERNEL";
+
+ case FD_TYPE_EPOLL:
+ return "FD_TYPE_EPOLL";
+
+ case FD_TYPE_VCOM_SOCKET:
+ return "FD_TYPE_VCOM_SOCKET";
+
+ default:
+ return "FD_TYPE_UNKNOWN";
+ }
+}
+
static inline int
vcom_socket_type_is_vppcom_bound (vcom_socket_type_t t)
{
return t == SOCKET_TYPE_VPPCOM_BOUND;
}
+static inline int
+vcom_socket_epoll_type_is_vppcom_bound (vcom_epoll_type_t t)
+{
+ return t == EPOLL_TYPE_VPPCOM_BOUND;
+}
+
static inline void
vsocket_init (vcom_socket_t * vsock)
{
+ memset (vsock, 0, sizeof (*vsock));
+
vsock->fd = INVALID_FD;
vsock->sid = INVALID_SESSION_ID;
vsock->type = SOCKET_TYPE_UNBOUND;
@@ -81,7 +208,43 @@ vsocket_init (vcom_socket_t * vsock)
}
static inline void
-vsocket_set (vcom_socket_t * vsock, i32 fd, i32 sid, vcom_socket_type_t type)
+vepoll_init (vcom_epoll_t * vepoll)
+{
+ memset (vepoll, 0, sizeof (*vepoll));
+
+ vepoll->epfd = INVALID_EPFD;
+ vepoll->vep_idx = INVALID_VEP_IDX;
+ vepoll->type = EPOLL_TYPE_UNBOUND;
+ vepoll->flags = 0;
+
+ vepoll->count = 0;
+ vepoll->close = 0;
+ /* vcom epoll attributes init here */
+}
+
+static inline void
+vepitem_init (vcom_epitem_t * vepitem)
+{
+ struct epoll_event event = {.events = 0, .data.fd = INVALID_FD};
+
+ memset (vepitem, 0, sizeof (*vepitem));
+
+ vepitem->epfd = INVALID_EPFD;
+
+ vepitem->fd = INVALID_FD;
+ vepitem->next_fd = INVALID_FD;
+ vepitem->prev_fd = INVALID_FD;
+
+ vepitem->type = FD_TYPE_INVALID;
+
+ vepitem->event = event;
+ vepitem->revent = event;
+ /* vepoll attributes init here */
+}
+
+static inline void
+vsocket_set (vcom_socket_t * vsock,
+ i32 fd, i32 sid, vcom_socket_type_t type)
{
vsock->fd = fd;
vsock->sid = sid;
@@ -89,15 +252,52 @@ vsocket_set (vcom_socket_t * vsock, i32 fd, i32 sid, vcom_socket_type_t type)
/* vcom socket attributes set here */
}
+static inline void
+vepoll_set (vcom_epoll_t * vepoll,
+ i32 epfd, i32 vep_idx,
+ vcom_epoll_type_t type, i32 flags, i32 count, u32 close)
+{
+ vepoll->epfd = epfd;
+ vepoll->vep_idx = vep_idx;
+ vepoll->type = type;
+ vepoll->flags = flags;
+
+ vepoll->count = count;
+ vepoll->close = close;
+ /* vcom epoll attributes set here */
+}
+
+static inline void
+vepitem_set (vcom_epitem_t * vepitem,
+ i32 epfd,
+ i32 fd, i32 next_fd, i32 prev_fd,
+ vcom_fd_type_t type,
+ struct epoll_event event, struct epoll_event revent)
+{
+ vepitem->epfd = epfd;
+
+ vepitem->fd = fd;
+ vepitem->next_fd = next_fd;
+ vepitem->prev_fd = prev_fd;
+
+ vepitem->type = type;
+
+ vepitem->event = event;
+ vepitem->revent = revent;
+ /* vcom epitem attributes set here */
+}
+
static inline int
vsocket_is_vppcom_bound (vcom_socket_t * vsock)
{
return vcom_socket_type_is_vppcom_bound (vsock->type);
}
-int vcom_socket_open_socket (int domain, int type, int protocol);
-
-int vcom_socket_close_socket (int fd);
+static inline int
+vepoll_is_vppcom_bound (vcom_epoll_t * vepoll)
+{
+ return vcom_socket_epoll_type_is_vppcom_bound (vepoll->type);
+}
int vcom_socket_main_init (void);
@@ -107,6 +307,9 @@ void vcom_socket_main_show (void);
int vcom_socket_is_vcom_fd (int fd);
+int
+vcom_socket_is_vcom_epfd (int epfd);
+
int vcom_socket_close (int __fd);
ssize_t vcom_socket_read (int __fd, void *__buf, size_t __nbytes);
@@ -117,29 +320,29 @@ int vcom_socket_fcntl_va (int __fd, int __cmd, va_list __ap);
int
vcom_socket_select (int vcom_nfds, fd_set * __restrict vcom_readfds,
- fd_set * __restrict vcom_writefds,
- fd_set * __restrict vcom_exceptfds,
- struct timeval *__restrict timeout);
+ fd_set * __restrict vcom_writefds,
+ fd_set * __restrict vcom_exceptfds,
+ struct timeval *__restrict timeout);
int vcom_socket_socket (int __domain, int __type, int __protocol);
int
vcom_socket_socketpair (int __domain, int __type, int __protocol,
- int __fds[2]);
+ int __fds[2]);
int vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
int
vcom_socket_getsockname (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len);
+ socklen_t * __restrict __len);
int
vcom_socket_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
int
vcom_socket_getpeername (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __len);
+ socklen_t * __restrict __len);
ssize_t
vcom_socket_send (int __fd, const void *__buf, size_t __n, int __flags);
@@ -154,13 +357,13 @@ int vcom_socket_is_connection_mode_socket (int __fd);
ssize_t
vcom_socket_sendto (int __fd, const void *__buf, size_t __n,
- int __flags, __CONST_SOCKADDR_ARG __addr,
- socklen_t __addr_len);
+ int __flags, __CONST_SOCKADDR_ARG __addr,
+ socklen_t __addr_len);
ssize_t
vcom_socket_recvfrom (int __fd, void *__restrict __buf, size_t __n,
- int __flags, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len);
+ int __flags, __SOCKADDR_ARG __addr,
+ socklen_t * __restrict __addr_len);
ssize_t
vcom_socket_sendmsg (int __fd, const struct msghdr *__message, int __flags);
@@ -168,7 +371,7 @@ vcom_socket_sendmsg (int __fd, const struct msghdr *__message, int __flags);
#ifdef __USE_GNU
int
vcom_socket_sendmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags);
+ unsigned int __vlen, int __flags);
#endif
ssize_t vcom_socket_recvmsg (int __fd, struct msghdr *__message, int __flags);
@@ -176,33 +379,45 @@ ssize_t vcom_socket_recvmsg (int __fd, struct msghdr *__message, int __flags);
#ifdef __USE_GNU
int
vcom_socket_recvmmsg (int __fd, struct mmsghdr *__vmessages,
- unsigned int __vlen, int __flags,
- struct timespec *__tmo);
+ unsigned int __vlen, int __flags,
+ struct timespec *__tmo);
#endif
int
vcom_socket_getsockopt (int __fd, int __level, int __optname,
- void *__restrict __optval,
- socklen_t * __restrict __optlen);
+ void *__restrict __optval,
+ socklen_t * __restrict __optlen);
int
vcom_socket_setsockopt (int __fd, int __level, int __optname,
- const void *__optval, socklen_t __optlen);
+ const void *__optval, socklen_t __optlen);
int vcom_socket_listen (int __fd, int __n);
int
vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len);
+ socklen_t * __restrict __addr_len);
#ifdef __USE_GNU
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
- socklen_t * __restrict __addr_len, int __flags);
+ socklen_t * __restrict __addr_len, int __flags);
#endif
int vcom_socket_shutdown (int __fd, int __how);
+int
+vcom_socket_epoll_create1 (int __flags);
+
+int
+vcom_socket_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event);
+
+int
+vcom_socket_epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss);
+
#endif /* included_vcom_socket_h */
/*
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.c b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.c
index 8fe7e1d..cadac92 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.c
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.c
@@ -103,13 +103,13 @@ static pthread_mutex_t libc_symbol_binding_mutex = PTHREAD_MUTEX_INITIALIZER;
#else
static void
swrap_log (enum swrap_dbglvl_e dbglvl, const char *func,
- const char *format, ...)
+ const char *format, ...)
PRINTF_ATTRIBUTE (3, 4);
#define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__)
static void
swrap_log (enum swrap_dbglvl_e dbglvl,
- const char *func, const char *format, ...)
+ const char *func, const char *format, ...)
{
char buffer[1024];
va_list va;
@@ -122,28 +122,28 @@ PRINTF_ATTRIBUTE (3, 4);
if (lvl >= dbglvl)
{
switch (dbglvl)
- {
- case SWRAP_LOG_ERROR:
- fprintf (stderr,
- "SWRAP_ERROR(%d) - %s: %s\n",
- (int) getpid (), func, buffer);
- break;
- case SWRAP_LOG_WARN:
- fprintf (stderr,
- "SWRAP_WARN(%d) - %s: %s\n",
- (int) getpid (), func, buffer);
- break;
- case SWRAP_LOG_DEBUG:
- fprintf (stderr,
- "SWRAP_DEBUG(%d) - %s: %s\n",
- (int) getpid (), func, buffer);
- break;
- case SWRAP_LOG_TRACE:
- fprintf (stderr,
- "SWRAP_TRACE(%d) - %s: %s\n",
- (int) getpid (), func, buffer);
- break;
- }
+ {
+ case SWRAP_LOG_ERROR:
+ fprintf (stderr,
+ "SWRAP_ERROR(%d) - %s: %s\n",
+ (int) getpid (), func, buffer);
+ break;
+ case SWRAP_LOG_WARN:
+ fprintf (stderr,
+ "SWRAP_WARN(%d) - %s: %s\n",
+ (int) getpid (), func, buffer);
+ break;
+ case SWRAP_LOG_DEBUG:
+ fprintf (stderr,
+ "SWRAP_DEBUG(%d) - %s: %s\n",
+ (int) getpid (), func, buffer);
+ break;
+ case SWRAP_LOG_TRACE:
+ fprintf (stderr,
+ "SWRAP_TRACE(%d) - %s: %s\n",
+ (int) getpid (), func, buffer);
+ break;
+ }
}
}
#endif
@@ -155,18 +155,18 @@ PRINTF_ATTRIBUTE (3, 4);
#ifdef HAVE_ACCEPT4
typedef int (*__libc_accept4) (int sockfd,
- struct sockaddr * addr,
- socklen_t * addrlen, int flags);
+ struct sockaddr * addr,
+ socklen_t * addrlen, int flags);
#else
typedef int (*__libc_accept) (int sockfd,
- struct sockaddr * addr, socklen_t * addrlen);
+ struct sockaddr * addr, socklen_t * addrlen);
#endif
typedef int (*__libc_bind) (int sockfd,
- const struct sockaddr * addr, socklen_t addrlen);
+ const struct sockaddr * addr, socklen_t addrlen);
typedef int (*__libc_close) (int fd);
typedef int (*__libc_connect) (int sockfd,
- const struct sockaddr * addr,
- socklen_t addrlen);
+ const struct sockaddr * addr,
+ socklen_t addrlen);
#if 0
/* TBD: dup and dup2 to be implemented later */
@@ -183,15 +183,15 @@ typedef FILE *(*__libc_fopen64) (const char *name, const char *mode);
typedef int (*__libc_eventfd) (int count, int flags);
#endif
typedef int (*__libc_getpeername) (int sockfd,
- struct sockaddr * addr,
- socklen_t * addrlen);
+ struct sockaddr * addr,
+ socklen_t * addrlen);
typedef int (*__libc_getsockname) (int sockfd,
- struct sockaddr * addr,
- socklen_t * addrlen);
+ struct sockaddr * addr,
+ socklen_t * addrlen);
typedef int (*__libc_getsockopt) (int sockfd,
- int level,
- int optname,
- void *optval, socklen_t * optlen);
+ int level,
+ int optname,
+ void *optval, socklen_t * optlen);
typedef int (*__libc_ioctl) (int d, unsigned long int request, ...);
typedef int (*__libc_listen) (int sockfd, int backlog);
typedef int (*__libc_open) (const char *pathname, int flags, mode_t mode);
@@ -202,53 +202,68 @@ typedef int (*__libc_openat) (int dirfd, const char *path, int flags, ...);
typedef int (*__libc_pipe) (int pipefd[2]);
typedef int (*__libc_read) (int fd, void *buf, size_t count);
typedef ssize_t (*__libc_readv) (int fd, const struct iovec * iov,
- int iovcnt);
+ int iovcnt);
typedef int (*__libc_recv) (int sockfd, void *buf, size_t len, int flags);
typedef int (*__libc_recvfrom) (int sockfd,
- void *buf,
- size_t len,
- int flags,
- struct sockaddr * src_addr,
- socklen_t * addrlen);
+ void *buf,
+ size_t len,
+ int flags,
+ struct sockaddr * src_addr,
+ socklen_t * addrlen);
typedef int (*__libc_recvmsg) (int sockfd, const struct msghdr * msg,
- int flags);
+ int flags);
typedef int (*__libc_send) (int sockfd, const void *buf, size_t len,
- int flags);
+ int flags);
typedef int (*__libc_sendmsg) (int sockfd, const struct msghdr * msg,
- int flags);
+ int flags);
typedef int (*__libc_sendto) (int sockfd, const void *buf, size_t len,
- int flags, const struct sockaddr * dst_addr,
- socklen_t addrlen);
+ int flags, const struct sockaddr * dst_addr,
+ socklen_t addrlen);
typedef int (*__libc_setsockopt) (int sockfd, int level, int optname,
- const void *optval, socklen_t optlen);
+ const void *optval, socklen_t optlen);
#ifdef HAVE_SIGNALFD
typedef int (*__libc_signalfd) (int fd, const sigset_t * mask, int flags);
#endif
typedef int (*__libc_socket) (int domain, int type, int protocol);
typedef int (*__libc_socketpair) (int domain, int type, int protocol,
- int sv[2]);
+ int sv[2]);
#ifdef HAVE_TIMERFD_CREATE
typedef int (*__libc_timerfd_create) (int clockid, int flags);
#endif
typedef ssize_t (*__libc_write) (int fd, const void *buf, size_t count);
typedef ssize_t (*__libc_writev) (int fd, const struct iovec * iov,
- int iovcnt);
+ int iovcnt);
typedef int (*__libc_shutdown) (int fd, int how);
typedef int (*__libc_select) (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval * __restrict __timeout);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval * __restrict __timeout);
#ifdef __USE_XOPEN2K
typedef int (*__libc_pselect) (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec * __restrict __timeout,
- const __sigset_t * __restrict __sigmask);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec * __restrict __timeout,
+ const __sigset_t * __restrict __sigmask);
#endif
+typedef int (*__libc_epoll_create) (int __size);
+
+typedef int (*__libc_epoll_create1) (int __flags);
+
+typedef int (*__libc_epoll_ctl) (int __epfd, int __op, int __fd,
+ struct epoll_event *__event);
+
+typedef int (*__libc_epoll_wait) (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+typedef int (*__libc_epoll_pwait) (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss);
+
+
#define SWRAP_SYMBOL_ENTRY(i) \
union { \
__libc_##i f; \
@@ -314,6 +329,11 @@ struct swrap_libc_symbols
#ifdef __USE_XOPEN2K
SWRAP_SYMBOL_ENTRY (pselect);
#endif
+ SWRAP_SYMBOL_ENTRY (epoll_create);
+ SWRAP_SYMBOL_ENTRY (epoll_create1);
+ SWRAP_SYMBOL_ENTRY (epoll_ctl);
+ SWRAP_SYMBOL_ENTRY (epoll_wait);
+ SWRAP_SYMBOL_ENTRY (epoll_pwait);
};
struct swrap
@@ -367,35 +387,35 @@ swrap_load_lib_handle (enum swrap_lib lib)
handle = swrap.libc.handle;
#ifdef LIBC_SO
if (handle == NULL)
- {
- handle = dlopen (LIBC_SO, flags);
+ {
+ handle = dlopen (LIBC_SO, flags);
- swrap.libc.handle = handle;
- }
+ swrap.libc.handle = handle;
+ }
#endif
if (handle == NULL)
- {
- for (i = 10; i >= 0; i--)
- {
- char soname[256] = { 0 };
-
- snprintf (soname, sizeof (soname), "libc.so.%d", i);
- handle = dlopen (soname, flags);
- if (handle != NULL)
- {
- break;
- }
- }
-
- swrap.libc.handle = handle;
- }
+ {
+ for (i = 10; i >= 0; i--)
+ {
+ char soname[256] = { 0 };
+
+ snprintf (soname, sizeof (soname), "libc.so.%d", i);
+ handle = dlopen (soname, flags);
+ if (handle != NULL)
+ {
+ break;
+ }
+ }
+
+ swrap.libc.handle = handle;
+ }
break;
}
if (handle == NULL)
{
SWRAP_LOG (SWRAP_LOG_ERROR,
- "Failed to dlopen library: %s\n", dlerror ());
+ "Failed to dlopen library: %s\n", dlerror ());
exit (-1);
}
@@ -414,12 +434,12 @@ _swrap_bind_symbol (enum swrap_lib lib, const char *fn_name)
if (func == NULL)
{
SWRAP_LOG (SWRAP_LOG_ERROR,
- "Failed to find %s: %s\n", fn_name, dlerror ());
+ "Failed to find %s: %s\n", fn_name, dlerror ());
exit (-1);
}
SWRAP_LOG (SWRAP_LOG_TRACE,
- "Loaded %s from %s", fn_name, swrap_str_lib (lib));
+ "Loaded %s from %s", fn_name, swrap_str_lib (lib));
return func;
}
@@ -443,7 +463,7 @@ _swrap_bind_symbol (enum swrap_lib lib, const char *fn_name)
#ifdef HAVE_ACCEPT4
int
libc_accept4 (int sockfd,
- struct sockaddr *addr, socklen_t * addrlen, int flags)
+ struct sockaddr *addr, socklen_t * addrlen, int flags)
{
swrap_bind_symbol_libc (accept4);
@@ -529,8 +549,8 @@ libc_vfcntl (int fd, int cmd, va_list ap)
}
rc = swrap.libc.symbols._libc_fcntl.f (fd,
- cmd,
- args[0], args[1], args[2], args[3]);
+ cmd,
+ args[0], args[1], args[2], args[3]);
return rc;
}
@@ -553,13 +573,13 @@ libc_getsockname (int sockfd, struct sockaddr *addr, socklen_t * addrlen)
int
libc_getsockopt (int sockfd,
- int level, int optname, void *optval, socklen_t * optlen)
+ int level, int optname, void *optval, socklen_t * optlen)
{
swrap_bind_symbol_libc (getsockopt);
return swrap.libc.symbols._libc_getsockopt.f (sockfd,
- level,
- optname, optval, optlen);
+ level,
+ optname, optval, optlen);
}
int
@@ -588,15 +608,15 @@ libc_recv (int sockfd, void *buf, size_t len, int flags)
int
libc_recvfrom (int sockfd,
- void *buf,
- size_t len,
- int flags, struct sockaddr *src_addr, socklen_t * addrlen)
+ void *buf,
+ size_t len,
+ int flags, struct sockaddr *src_addr, socklen_t * addrlen)
{
swrap_bind_symbol_libc (recvfrom);
return swrap.libc.symbols._libc_recvfrom.f (sockfd,
- buf,
- len, flags, src_addr, addrlen);
+ buf,
+ len, flags, src_addr, addrlen);
}
int
@@ -625,26 +645,26 @@ libc_sendmsg (int sockfd, const struct msghdr *msg, int flags)
int
libc_sendto (int sockfd,
- const void *buf,
- size_t len,
- int flags, const struct sockaddr *dst_addr, socklen_t addrlen)
+ const void *buf,
+ size_t len,
+ int flags, const struct sockaddr *dst_addr, socklen_t addrlen)
{
swrap_bind_symbol_libc (sendto);
return swrap.libc.symbols._libc_sendto.f (sockfd,
- buf,
- len, flags, dst_addr, addrlen);
+ buf,
+ len, flags, dst_addr, addrlen);
}
int
libc_setsockopt (int sockfd,
- int level, int optname, const void *optval, socklen_t optlen)
+ int level, int optname, const void *optval, socklen_t optlen)
{
swrap_bind_symbol_libc (setsockopt);
return swrap.libc.symbols._libc_setsockopt.f (sockfd,
- level,
- optname, optval, optlen);
+ level,
+ optname, optval, optlen);
}
int
@@ -681,34 +701,77 @@ libc_shutdown (int fd, int how)
int
libc_select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout)
{
swrap_bind_symbol_libc (select);
return swrap.libc.symbols._libc_select.f (__nfds, __readfds,
- __writefds,
- __exceptfds, __timeout);
+ __writefds,
+ __exceptfds, __timeout);
}
#ifdef __USE_XOPEN2K
int
libc_pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask)
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask)
{
swrap_bind_symbol_libc (pselect);
return swrap.libc.symbols._libc_pselect.f (__nfds, __readfds,
- __writefds,
- __exceptfds,
- __timeout, __sigmask);
+ __writefds,
+ __exceptfds,
+ __timeout, __sigmask);
}
#endif
+int libc_epoll_create (int __size)
+{
+ swrap_bind_symbol_libc (epoll_create);
+
+ return swrap.libc.symbols._libc_epoll_create.f (__size);
+}
+
+int libc_epoll_create1 (int __flags)
+{
+ swrap_bind_symbol_libc (epoll_create1);
+
+ return swrap.libc.symbols._libc_epoll_create1.f (__flags);
+}
+
+int libc_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event)
+{
+ swrap_bind_symbol_libc (epoll_ctl);
+
+ return swrap.libc.symbols._libc_epoll_ctl.f (__epfd, __op, __fd,
+ __event);
+}
+
+int libc_epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout)
+{
+ swrap_bind_symbol_libc (epoll_wait);
+
+ return swrap.libc.symbols._libc_epoll_wait.f (__epfd, __events,
+ __maxevents, __timeout);
+}
+
+int libc_epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss)
+{
+ swrap_bind_symbol_libc (epoll_pwait);
+
+ return swrap.libc.symbols._libc_epoll_pwait.f (__epfd, __events,
+ __maxevents, __timeout,
+ __ss);
+}
+
static void
swrap_thread_prepare (void)
{
@@ -739,7 +802,7 @@ swrap_constructor (void)
* This should prevent such deadlocks.
*/
pthread_atfork (&swrap_thread_prepare,
- &swrap_thread_parent, &swrap_thread_child);
+ &swrap_thread_parent, &swrap_thread_child);
}
/****************************
diff --git a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.h b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.h
index e3590d6..8ca8bb6 100644
--- a/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.h
+++ b/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket_wrapper.h
@@ -62,6 +62,7 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/select.h>
+#include <sys/epoll.h>
#include <sys/uio.h>
#include <stdlib.h>
@@ -105,7 +106,7 @@
#ifdef HAVE_ACCEPT4
int
libc_accept4 (int sockfd,
- struct sockaddr *addr, socklen_t * addrlen, int flags);
+ struct sockaddr *addr, socklen_t * addrlen, int flags);
#else /* HAVE_ACCEPT4 */
int libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen);
#endif /* HAVE_ACCEPT4 */
@@ -136,7 +137,7 @@ int libc_getsockname (int sockfd, struct sockaddr *addr, socklen_t * addrlen);
int
libc_getsockopt (int sockfd,
- int level, int optname, void *optval, socklen_t * optlen);
+ int level, int optname, void *optval, socklen_t * optlen);
int libc_listen (int sockfd, int backlog);
@@ -146,9 +147,9 @@ int libc_recv (int sockfd, void *buf, size_t len, int flags);
int
libc_recvfrom (int sockfd,
- void *buf,
- size_t len,
- int flags, struct sockaddr *src_addr, socklen_t * addrlen);
+ void *buf,
+ size_t len,
+ int flags, struct sockaddr *src_addr, socklen_t * addrlen);
int libc_recvmsg (int sockfd, struct msghdr *msg, int flags);
@@ -158,14 +159,14 @@ int libc_sendmsg (int sockfd, const struct msghdr *msg, int flags);
int
libc_sendto (int sockfd,
- const void *buf,
- size_t len,
- int flags, const struct sockaddr *dst_addr, socklen_t addrlen);
+ const void *buf,
+ size_t len,
+ int flags, const struct sockaddr *dst_addr, socklen_t addrlen);
int
libc_setsockopt (int sockfd,
- int level, int optname, const void *optval,
- socklen_t optlen);
+ int level, int optname, const void *optval,
+ socklen_t optlen);
int libc_socket (int domain, int type, int protocol);
@@ -177,19 +178,33 @@ int libc_shutdown (int fd, int how);
int
libc_select (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- struct timeval *__restrict __timeout);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ struct timeval *__restrict __timeout);
#ifdef __USE_XOPEN2K
int
libc_pselect (int __nfds, fd_set * __restrict __readfds,
- fd_set * __restrict __writefds,
- fd_set * __restrict __exceptfds,
- const struct timespec *__restrict __timeout,
- const __sigset_t * __restrict __sigmask);
+ fd_set * __restrict __writefds,
+ fd_set * __restrict __exceptfds,
+ const struct timespec *__restrict __timeout,
+ const __sigset_t * __restrict __sigmask);
#endif
+int libc_epoll_create (int __size);
+
+int libc_epoll_create1 (int __flags);
+
+int libc_epoll_ctl (int __epfd, int __op, int __fd,
+ struct epoll_event *__event);
+
+int libc_epoll_wait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout);
+
+int libc_epoll_pwait (int __epfd, struct epoll_event *__events,
+ int __maxevents, int __timeout,
+ const __sigset_t *__ss);
+
void swrap_constructor (void);
void swrap_destructor (void);