X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvcom.c;h=24b8f2985ebd0a8378dff577557dd19caad47ffd;hb=ee45d41a10c3459fc11e7d037fc411fd4cdfd495;hp=6d98fdb75c0518e7132856a6006c9665c8ea7b87;hpb=5c7cf1cc5358d137160be1619981e7eea9a7402f;p=vpp.git diff --git a/src/vcl/vcom.c b/src/vcl/vcom.c index 6d98fdb75c0..24b8f2985eb 100644 --- a/src/vcl/vcom.c +++ b/src/vcl/vcom.c @@ -98,7 +98,7 @@ static int is_vcom_init; * RETURN: 0 on success -1 on failure * */ static inline int -vcom_init () +vcom_init (void) { pid_t pid = getpid (); @@ -196,12 +196,10 @@ close (int __fd) if (is_vcom_socket_fd (__fd) || is_vcom_epfd (__fd)) { if (VCOM_DEBUG > 0) - vcom_socket_main_show (); + fprintf (stderr, "[%d] close: fd %d\n", pid, __fd); rv = vcom_close (__fd); if (VCOM_DEBUG > 0) - fprintf (stderr, "[%d] close: " "'%04d'='%04d'\n", pid, rv, __fd); - if (VCOM_DEBUG > 0) - vcom_socket_main_show (); + fprintf (stderr, "[%d] close: vcom_close() returned %d\n", pid, rv); if (rv != 0) { errno = -rv; @@ -1282,13 +1280,8 @@ vcom_select (int __nfds, fd_set * __restrict __readfds, * */ vcom_fd_set_merge ( /* dest, select sets */ - __readfds || __writefds || __exceptfds ? - &new_nfds : NULL, - __readfds, - __writefds, - __exceptfds, - __readfds || __writefds || __exceptfds ? - &new_nfd : NULL, + &new_nfds, + __readfds, __writefds, __exceptfds, &new_nfd, /* src1, vcom sets */ vcom_nfds, __readfds ? &vcom_readfds : NULL, @@ -1958,6 +1951,12 @@ vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) case AF_INET: case AF_INET6: rv = vcom_socket_connect (__fd, __addr, __len); + if (!rv) + { + errno = -rv; + return -1; + + } break; default: @@ -1984,7 +1983,7 @@ connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len) "'%04d'='%04d', '%p', '%04d'\n", pid, (unsigned long) tid, (unsigned long) tid, rv, __fd, __addr, __len); - if (rv != 0) + if (!rv) { errno = -rv; return -1; @@ -2075,6 +2074,46 @@ send (int __fd, const void *__buf, size_t __n, int __flags) return libc_send (__fd, __buf, __n, __flags); } +ssize_t +sendfile (int __out_fd, int __in_fd, off_t * __offset, size_t __len) +{ + ssize_t size; + + if (VCOM_DEBUG > 2) + clib_warning ("[%d] __out_fd %d, __in_fd %d, __offset %p, __len %ld", + getpid (), __out_fd, __in_fd, __offset, __len); + + if (is_vcom_socket_fd (__out_fd)) + { + /* TBD: refactor this check to be part of is_vcom_socket_fd() */ + if (vcom_init () != 0) + return -1; + + size = vcom_socket_sendfile (__out_fd, __in_fd, __offset, __len); + if (VCOM_DEBUG > 2) + clib_warning ("[%d] vcom_socket_sendfile (out_fd %d, in_fd %d, " + "offset %p (%ld), len %lu) returned %ld", + getpid (), __out_fd, __in_fd, __offset, + __offset ? *__offset : -1, __len, size); + if (size < 0) + { + errno = -size; + return -1; + } + return size; + } + if (VCOM_DEBUG > 2) + clib_warning ("[%d] calling libc_sendfile!", getpid ()); + return libc_sendfile (__out_fd, __in_fd, __offset, __len); +} + +ssize_t +sendfile64 (int __out_fd, int __in_fd, off_t * __offset, size_t __len) +{ + return sendfile (__out_fd, __in_fd, __offset, __len); +} + + /* * Read N bytes into BUF from socket FD. * Returns the number read or -1 for errors. @@ -2573,7 +2612,6 @@ accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len) return libc_accept (__fd, __addr, __addr_len); } -#ifdef __USE_GNU /* * Similar to 'accept' but takes an additional parameter to specify * flags. @@ -2597,9 +2635,14 @@ int accept4 (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len, int __flags) { - int rv; + int rv = 0; pid_t pid = getpid (); + fprintf (stderr, + "[%d] accept4: in the beginning... " + "'%04d'='%04d', '%p', '%p', '%04x'\n", + pid, rv, __fd, __addr, __addr_len, __flags); + if (is_vcom_socket_fd (__fd)) { if (VCOM_DEBUG > 0) @@ -2607,7 +2650,7 @@ accept4 (int __fd, __SOCKADDR_ARG __addr, rv = vcom_accept4 (__fd, __addr, __addr_len, __flags); if (VCOM_DEBUG > 0) fprintf (stderr, - "[%d] accept4: " + "[%d] accept4: VCL " "'%04d'='%04d', '%p', '%p', '%04x'\n", pid, rv, __fd, __addr, __addr_len, __flags); if (VCOM_DEBUG > 0) @@ -2619,11 +2662,14 @@ accept4 (int __fd, __SOCKADDR_ARG __addr, } return rv; } + fprintf (stderr, + "[%d] accept4: libc " + "'%04d'='%04d', '%p', '%p', '%04x'\n", + pid, rv, __fd, __addr, __addr_len, __flags); + return libc_accept4 (__fd, __addr, __addr_len, __flags); } -#endif - /* * Shut down all or part of the connection open on socket FD. * HOW determines what to shut down: @@ -2797,54 +2843,19 @@ epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event) int rv; pid_t pid = getpid (); - if (is_vcom_epfd (__epfd)) - { - /* TBD: currently limiting epoll to support only vcom fds */ - if (is_vcom_socket_fd (__fd)) - { - rv = vcom_epoll_ctl (__epfd, __op, __fd, __event); - if (VCOM_DEBUG > 0) - fprintf (stderr, - "[%d] epoll_ctl: " - "'%04d'='%04d', '%04d', '%04d'\n", - pid, rv, __epfd, __op, __fd); - if (rv != 0) - { - errno = -rv; - return -1; - } - return 0; - } - else - { - /* - * TBD: currently epoll does not support kernel fds - * or epoll fds */ - errno = EBADF; - return -1; - } - } - else + rv = vcom_epoll_ctl (__epfd, __op, __fd, __event); + if (VCOM_DEBUG > 0) + fprintf (stderr, + "[%d] epoll_ctl: " + "'%04d'='%04d', '%04d', '%04d'\n", pid, rv, __epfd, __op, __fd); + if (rv != 0) { - /* epfd is not an epoll file descriptor */ - errno = EINVAL; + errno = -rv; return -1; } return 0; } -int -vcom_epoll_wait (int __epfd, struct epoll_event *__events, - int __maxevents, int __timeout) -{ - if (vcom_init () != 0) - { - return -1; - } - - return vcom_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL); -} - int epoll_wait (int __epfd, struct epoll_event *__events, int __maxevents, int __timeout) @@ -2854,49 +2865,29 @@ epoll_wait (int __epfd, struct epoll_event *__events, if (__maxevents <= 0 || __maxevents > EP_MAX_EVENTS) { + fprintf (stderr, "[%d] ERROR: epoll_wait() invalid maxevents %d\n", + pid, __maxevents); errno = EINVAL; return -1; } - if (is_vcom_epfd (__epfd)) - { - rv = vcom_epoll_wait (__epfd, __events, __maxevents, __timeout); - if (VCOM_DEBUG > 0) - fprintf (stderr, - "[%d] epoll_wait: " - "'%04d'='%04d', '%p', " - "'%04d', '%04d'\n", - pid, rv, __epfd, __events, __maxevents, __timeout); - if (rv < 0) - { - errno = -rv; - return -1; - } - return rv; - } - else + rv = + vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout, NULL); + if (VCOM_DEBUG > 2) + fprintf (stderr, + "[%d] epoll_wait: " + "'%04d'='%04d', '%p', " + "'%04d', '%04d'\n", + pid, rv, __epfd, __events, __maxevents, __timeout); + if (rv < 0) { - errno = EINVAL; + errno = -rv; return -1; } - return 0; + return rv; } -int -vcom_epoll_pwait (int __epfd, struct epoll_event *__events, - int __maxevents, int __timeout, const __sigset_t * __ss) -{ - if (vcom_init () != 0) - { - return -1; - } - - /* implementation */ - return vcom_socket_epoll_pwait (__epfd, __events, - __maxevents, __timeout, __ss); -} - int epoll_pwait (int __epfd, struct epoll_event *__events, int __maxevents, int __timeout, const __sigset_t * __ss) @@ -2912,7 +2903,9 @@ epoll_pwait (int __epfd, struct epoll_event *__events, if (is_vcom_epfd (__epfd)) { - rv = vcom_epoll_pwait (__epfd, __events, __maxevents, __timeout, __ss); + rv = + vcom_socket_epoll_pwait (__epfd, __events, __maxevents, __timeout, + __ss); if (VCOM_DEBUG > 0) fprintf (stderr, "[%d] epoll_pwait: "