Change-Id: I56567953fb8329315393047913e30fc7f2242bdb
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
-1.0 /* wait forever */ );
if (client_fd < 0)
errno = -client_fd;
-1.0 /* wait forever */ );
if (client_fd < 0)
errno = -client_fd;
+#elif HAVE_ACCEPT4
+ client_fd = accept4 (ssm->listen_fd, (struct sockaddr *) NULL, NULL, NULL);
#else
client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL);
#endif
#else
client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL);
#endif
return libc_accept (__fd, __addr, __addr_len);
}
return libc_accept (__fd, __addr, __addr_len);
}
/*
* Similar to 'accept' but takes an additional parameter to specify
* flags.
/*
* Similar to 'accept' but takes an additional parameter to specify
* flags.
accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags)
{
accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags)
{
+ fprintf (stderr,
+ "[%d] accept4: in the beginning... "
+ "'%04d'='%04d', '%p', '%p', '%04x'\n",
+ pid, rv, __fd, __addr, __addr_len, __flags);
+
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
if (is_vcom_socket_fd (__fd))
{
if (VCOM_DEBUG > 0)
rv = vcom_accept4 (__fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
fprintf (stderr,
rv = vcom_accept4 (__fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
fprintf (stderr,
"'%04d'='%04d', '%p', '%p', '%04x'\n",
pid, rv, __fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
"'%04d'='%04d', '%p', '%p', '%04x'\n",
pid, rv, __fd, __addr, __addr_len, __flags);
if (VCOM_DEBUG > 0)
+ fprintf (stderr,
+ "[%d] accept4: libc "
+ "'%04d'='%04d', '%p', '%p', '%04x'\n",
+ pid, rv, __fd, __addr, __addr_len, __flags);
+
return libc_accept4 (__fd, __addr, __addr_len, __flags);
}
return libc_accept4 (__fd, __addr, __addr_len, __flags);
}
/*
* Shut down all or part of the connection open on socket FD.
* HOW determines what to shut down:
/*
* Shut down all or part of the connection open on socket FD.
* HOW determines what to shut down:
rv =
vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL);
rv =
vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL);
fprintf (stderr,
"[%d] epoll_wait: "
"'%04d'='%04d', '%p', "
fprintf (stderr,
"[%d] epoll_wait: "
"'%04d'='%04d', '%p', "
extern int
accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
extern int
accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
/* Similar to 'accept' but takes an additional parameter to specify flags.
This function is a cancellation point and therefore not marked with
/* Similar to 'accept' but takes an additional parameter to specify flags.
This function is a cancellation point and therefore not marked with
extern int
accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags);
extern int
accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags);
/* Shut down all or part of the connection open on socket FD.
HOW determines what to shut down:
/* Shut down all or part of the connection open on socket FD.
HOW determines what to shut down:
- if (__cmd == FIONREAD)
- rv = vppcom_session_attr (__sid, VPPCOM_ATTR_GET_NREAD, 0, 0);
- else
- rv = -EOPNOTSUPP;
+ switch (__cmd)
+ {
+ case FIONREAD:
+ rv = vppcom_session_attr (__sid, VPPCOM_ATTR_GET_NREAD, 0, 0);
+ break;
+
+ case FIONBIO:
+ {
+ u32 flags = va_arg (__ap, int) ? O_NONBLOCK : 0;
+ u32 len = sizeof (flags);
+ rv = vppcom_session_attr (__sid, VPPCOM_ATTR_SET_FLAGS, &flags, &len);
+ }
+ break;
+
+ default:
+ rv = -EOPNOTSUPP;
+ break;
+ }
struct timeval *__restrict timeout)
{
static unsigned long vcom_nsid_fds = 0;
struct timeval *__restrict timeout)
{
static unsigned long vcom_nsid_fds = 0;
- vcom_socket_main_t *vsm = &vcom_socket_main;
int vcom_nsid = 0;
int rv = -EBADF;
int vcom_nsid = 0;
int rv = -EBADF;
if (VCOM_DEBUG > 0)
fprintf (stderr,
"[%d] vcom_socket_select called to "
if (VCOM_DEBUG > 0)
fprintf (stderr,
"[%d] vcom_socket_select called to "
- "emulate delay_ns()!\n", vsm->my_pid);
+ "emulate delay_ns()!\n", getpid ());
rv = vppcom_select (0, NULL, NULL, NULL, time_to_wait);
}
else
{
fprintf (stderr, "[%d] vcom_socket_select called vcom_nfds = 0 "
"and invalid time_to_wait (%f)!\n",
rv = vppcom_select (0, NULL, NULL, NULL, time_to_wait);
}
else
{
fprintf (stderr, "[%d] vcom_socket_select called vcom_nfds = 0 "
"and invalid time_to_wait (%f)!\n",
- vsm->my_pid, time_to_wait);
+ getpid (), time_to_wait);
NULL, time_to_wait);
if (VCOM_DEBUG > 2)
fprintf (stderr, "[%d] called vppcom_select(): "
NULL, time_to_wait);
if (VCOM_DEBUG > 2)
fprintf (stderr, "[%d] called vppcom_select(): "
- "'%04d'='%04d'\n", vsm->my_pid, rv, (int) vcom_nsid_fds);
+ "'%04d'='%04d'\n", getpid (), rv, (int) vcom_nsid_fds);
/* check if any file descriptors changed status */
if (rv > 0)
/* check if any file descriptors changed status */
if (rv > 0)
/* flags can be 0 or can be bitwise OR
* of any of SOCK_NONBLOCK and SOCK_CLOEXEC */
/* flags can be 0 or can be bitwise OR
* of any of SOCK_NONBLOCK and SOCK_CLOEXEC */
+ if (VCOM_DEBUG > 2)
+ fprintf (stderr, "[%d] vcom_socket_accept_flags: "
+ "fd = %d, __addr = %p, __addr_len = %p flags = %d (0x%x)\n",
+ getpid (), __fd, __addr, __addr_len, flags, flags);
+
if (!(!flags || (flags & (SOCK_NONBLOCK | SOCK_CLOEXEC))))
{
/* TBD: return proper error code */
if (!(!flags || (flags & (SOCK_NONBLOCK | SOCK_CLOEXEC))))
{
/* TBD: return proper error code */
+ fprintf (stderr, "[%d] ERROR: vcom_socket_accept_flags: "
+ "invalid flags = %d (0x%x)\n", getpid (), flags, flags);
+
if (!vcom_socket_is_connection_mode_socket (__fd))
{
if (!vcom_socket_is_connection_mode_socket (__fd))
{
+ fprintf (stderr, "[%d] ERROR: vcom_socket_accept_flags: "
+ "connection mode socket support TBD!\n", getpid ());
rv = vcom_fcntl (vsock->fd, F_GETFL, 0);
if (rv < 0)
{
rv = vcom_fcntl (vsock->fd, F_GETFL, 0);
if (rv < 0)
{
+ fprintf (stderr, "[%d] ERROR: vcom_socket_accept_flags: "
+ "vcom_fcnt() returned %d!\n", getpid (), rv);
+ if (rv != VPPCOM_EAGAIN)
+ fprintf (stderr, "[%d] ERROR: vcom_socket_accept_flags: "
+ "vppcom_session_accept() returned %d!", getpid (), rv);
&domain, &type, &protocol, flags);
if (fd < 0)
{
&domain, &type, &protocol, flags);
if (fd < 0)
{
+ fprintf (stderr, "[%d] ERROR: vcom_socket_accept_flags: "
+ "vcom_socket_connected_socket() returned %d!",
+ getpid (), rv);
- 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;
- }
- }
return vcom_socket_accept_flags (__fd, __addr, __addr_len, 0);
}
return vcom_socket_accept_flags (__fd, __addr, __addr_len, 0);
}
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags)
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
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);
}
/* SOCK_NONBLOCK and SOCK_CLOEXEC can be bitwise ORed in flags */
return vcom_socket_accept_flags (__fd, __addr, __addr_len, __flags);
}
/* TBD: move it to vppcom */
static inline int
/* TBD: move it to vppcom */
static inline int
struct epoll_event *__event,
int free_vepitem_on_del)
{
struct epoll_event *__event,
int free_vepitem_on_del)
{
- vcom_socket_main_t *vsm = &vcom_socket_main;
int rv = -1;
i32 cnt;
vcom_epoll_t *vepoll;
int rv = -1;
i32 cnt;
vcom_epoll_t *vepoll;
"[%d] vcom_socket_epoll_ctl_i: vppcom_epoll_ctl() "
"returned %d\n\tepfd %d, vep_idx %d, fd %d sid %d op %d"
"\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
"[%d] vcom_socket_epoll_ctl_i: vppcom_epoll_ctl() "
"returned %d\n\tepfd %d, vep_idx %d, fd %d sid %d op %d"
"\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
- vsm->my_pid, rv, __epfd, vep_idx, __fd, sid, __op,
+ getpid (), rv, __epfd, vep_idx, __fd, sid, __op,
vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
}
else
vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
}
else
"[%d] vcom_socket_epoll_ctl_i: libc_epoll_ctl() "
"returned %d\n\tepfd %d, vep_idx %d, fd %d sid %d op %d"
"\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
"[%d] vcom_socket_epoll_ctl_i: libc_epoll_ctl() "
"returned %d\n\tepfd %d, vep_idx %d, fd %d sid %d op %d"
"\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
- vsm->my_pid, rv, __epfd, vep_idx, __fd, sid, __op,
+ getpid (), rv, __epfd, vep_idx, __fd, sid, __op,
vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
}
vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
}
if (!__events || (__timeout < -1))
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: "
if (!__events || (__timeout < -1))
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: "
- "Bad args __events %p, __timeout %d\n", vsm->my_pid,
+ "Bad args __events %p, __timeout %d\n", getpid (),
__events, __timeout);
rv = -EFAULT;
goto out;
__events, __timeout);
rv = -EFAULT;
goto out;
if (vep_idx == INVALID_VEP_IDX)
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: "
if (vep_idx == INVALID_VEP_IDX)
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: "
- "Bad epoll fd %d\n", vsm->my_pid, __epfd);
+ "Bad epoll fd %d\n", getpid (), __epfd);
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: No events"
" in epfd!\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
{
fprintf (stderr, "[%d] ERROR: vcom_socket_epoll_pwait: No events"
" in epfd!\n\tcount %d, vcl_cnt %d, libc_cnt %d\n",
- vsm->my_pid, vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
+ getpid (), vepoll->count, vepoll->vcl_cnt, vepoll->libc_cnt);
rv = -EINVAL;
goto out;
}
if (vepoll->libc_cnt == 0)
{
rv = -EINVAL;
goto out;
}
if (vepoll->libc_cnt == 0)
{
+ if (VCOM_DEBUG > 2)
+ fprintf (stderr, "[%d] vcom_socket_epoll_pwait: libc_cnt = 0, "
+ "calling vppcom_epoll_wait()\n", getpid ());
rv = vppcom_epoll_wait (vep_idx, __events, __maxevents, time_to_wait);
}
else if (vepoll->vcl_cnt == 0)
{
rv = vppcom_epoll_wait (vep_idx, __events, __maxevents, time_to_wait);
}
else if (vepoll->vcl_cnt == 0)
{
+ if (VCOM_DEBUG > 2)
+ fprintf (stderr, "[%d] vcom_socket_epoll_pwait: vcl_cnt = 0, "
+ "calling libc_epoll_pwait()\n", getpid ());
rv = libc_epoll_pwait (__epfd, __events, __maxevents, __timeout, __ss);
}
else
{
rv = libc_epoll_pwait (__epfd, __events, __maxevents, __timeout, __ss);
}
else
{
+ if (VCOM_DEBUG > 2)
+ fprintf (stderr, "[%d] vcom_socket_epoll_pwait: vcl_cnt = %d, "
+ "libc_cnt = %d -> mixed polling\n", getpid (),
+ vepoll->vcl_cnt, vepoll->libc_cnt);
vec_validate (libc_ev, __maxevents);
timeout = clib_time_now (&vsm->clib_time) + time_to_wait;
do
vec_validate (libc_ev, __maxevents);
timeout = clib_time_now (&vsm->clib_time) + time_to_wait;
do
rv2 = libc_epoll_pwait (__epfd, libc_ev, __maxevents, 1, __ss);
if ((rv > 0) || (rv2 > 0))
{
rv2 = libc_epoll_pwait (__epfd, libc_ev, __maxevents, 1, __ss);
if ((rv > 0) || (rv2 > 0))
{
+ if (VCOM_DEBUG > 2)
+ fprintf (stderr, "[%d] vcom_socket_epoll_pwait: "
+ "rv = %d, rv2 = %d\n", getpid (), rv, rv2);
int n = __maxevents - rv;
n = rv2 <= n ? rv2 : n;
rv = (rv > 0) ? rv : 0;
int n = __maxevents - rv;
n = rv2 <= n ? rv2 : n;
rv = (rv > 0) ? rv : 0;
if (rv < 0)
fprintf (stderr,
"[%d] ERROR: vppcom_epoll_wait() returned %d\n",
if (rv < 0)
fprintf (stderr,
"[%d] ERROR: vppcom_epoll_wait() returned %d\n",
if (rv2 < 0)
{
fprintf (stderr,
"[%d] ERROR: libc_epoll_wait() failed, errno %d\n",
if (rv2 < 0)
{
fprintf (stderr,
"[%d] ERROR: libc_epoll_wait() failed, errno %d\n",
rv = (rv < 0) ? rv : -errno;
}
goto out;
rv = (rv < 0) ? rv : -errno;
}
goto out;
- vcom_socket_main_t *vsm = &vcom_socket_main;
nfds_t fds_idx = 0;
int nfd = 0;
nfds_t fds_idx = 0;
int nfd = 0;
if (VCOM_DEBUG > 2)
fprintf (stderr,
"[%d] vcom_socket_select: "
if (VCOM_DEBUG > 2)
fprintf (stderr,
"[%d] vcom_socket_select: "
- "'%04d'='%04d'\n", vsm->my_pid, vcom_nfd, vcom_nfds);
+ "'%04d'='%04d'\n", getpid (), vcom_nfd, vcom_nfds);
vsm->epitemidxs_by_fd = hash_create (0, sizeof (i32 *));
clib_time_init (&vsm->clib_time);
vsm->epitemidxs_by_fd = hash_create (0, sizeof (i32 *));
clib_time_init (&vsm->clib_time);
- vsm->my_pid = getpid ();
vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len);
vcom_socket_accept (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len);
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags);
int
vcom_socket_accept4 (int __fd, __SOCKADDR_ARG __addr,
socklen_t * __restrict __addr_len, int __flags);
int vcom_socket_shutdown (int __fd, int __how);
int vcom_socket_shutdown (int __fd, int __how);
* SWRAP LOADING LIBC FUNCTIONS
*********************************************************/
* SWRAP LOADING LIBC FUNCTIONS
*********************************************************/
typedef int (*__libc_accept4) (int sockfd,
struct sockaddr * addr,
socklen_t * addrlen, int flags);
typedef int (*__libc_accept4) (int sockfd,
struct sockaddr * addr,
socklen_t * addrlen, int flags);
typedef int (*__libc_accept) (int sockfd,
struct sockaddr * addr, socklen_t * addrlen);
typedef int (*__libc_accept) (int sockfd,
struct sockaddr * addr, socklen_t * addrlen);
typedef int (*__libc_bind) (int sockfd,
const struct sockaddr * addr, socklen_t addrlen);
typedef int (*__libc_close) (int fd);
typedef int (*__libc_bind) (int sockfd,
const struct sockaddr * addr, socklen_t addrlen);
typedef int (*__libc_close) (int fd);
struct swrap_libc_symbols
{
struct swrap_libc_symbols
{
SWRAP_SYMBOL_ENTRY (accept4);
SWRAP_SYMBOL_ENTRY (accept4);
SWRAP_SYMBOL_ENTRY (accept);
SWRAP_SYMBOL_ENTRY (accept);
SWRAP_SYMBOL_ENTRY (bind);
SWRAP_SYMBOL_ENTRY (close);
SWRAP_SYMBOL_ENTRY (connect);
SWRAP_SYMBOL_ENTRY (bind);
SWRAP_SYMBOL_ENTRY (close);
SWRAP_SYMBOL_ENTRY (connect);
* has probably something todo with with the linker.
* So we need load each function at the point it is called the first time.
*/
* has probably something todo with with the linker.
* So we need load each function at the point it is called the first time.
*/
int
libc_accept4 (int sockfd,
struct sockaddr *addr, socklen_t * addrlen, int flags)
int
libc_accept4 (int sockfd,
struct sockaddr *addr, socklen_t * addrlen, int flags)
return swrap.libc.symbols._libc_accept4.f (sockfd, addr, addrlen, flags);
}
return swrap.libc.symbols._libc_accept4.f (sockfd, addr, addrlen, flags);
}
-#else /* HAVE_ACCEPT4 */
-
int
libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen)
{
int
libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen)
{
return swrap.libc.symbols._libc_accept.f (sockfd, addr, addrlen);
}
return swrap.libc.symbols._libc_accept.f (sockfd, addr, addrlen);
}
-#endif /* HAVE_ACCEPT4 */
int
libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
int
libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
#include <poll.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <poll.h>
#include <sys/uio.h>
#include <stdlib.h>
/* GCC have printf type attribute check. */
/* GCC have printf type attribute check. */
* has probably something todo with with the linker.
* So we need load each function at the point it is called the first time.
*/
* has probably something todo with with the linker.
* So we need load each function at the point it is called the first time.
*/
-#ifdef HAVE_ACCEPT4
-int
-libc_accept4 (int sockfd,
- struct sockaddr *addr, socklen_t * addrlen, int flags);
-#else /* HAVE_ACCEPT4 */
+int libc_accept4 (int sockfd, struct sockaddr *addr, socklen_t * addrlen,
+ int flags);
+
int libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen);
int libc_accept (int sockfd, struct sockaddr *addr, socklen_t * addrlen);
-#endif /* HAVE_ACCEPT4 */
int libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int libc_bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen);
echo "set confirm off" >> $1
if [ -n "$4" ] ; then
echo "set exec-wrapper env LD_PRELOAD=$4" >> $1
echo "set confirm off" >> $1
if [ -n "$4" ] ; then
echo "set exec-wrapper env LD_PRELOAD=$4" >> $1