diff options
author | shrinivasan ganapathy <shrinivasanganapathy@gmail.com> | 2017-10-04 02:48:31 -0700 |
---|---|---|
committer | shrinivasan ganapathy <shrinivasanganapathy@gmail.com> | 2017-10-04 02:48:31 -0700 |
commit | 34956cc3d34d6e7b9c7ed5a27d9eebd6fe404280 (patch) | |
tree | 8828dcf092313a22b664c9de02c1201709548f48 /vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h | |
parent | 4cf3180c5a7cdd4e6a733ea2712ff2788c2e83ad (diff) |
VCL_LDPRELOAD epoll implementation
-epoll_create implementation
Change-Id: If05b5f44e48455f5a6f7a8096c1d020e7f3cd9cc
Signed-off-by: shrinivasan ganapathy <shrinivasanganapathy@gmail.com>
Diffstat (limited to 'vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h')
-rw-r--r-- | vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.h | 259 |
1 files changed, 237 insertions, 22 deletions
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 */ /* |