2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef included_vcom_h
17 #define included_vcom_h
20 /* Set VCOM_DEBUG 2 for connection debug, 3 for read/write debug output */
26 #include <vppinfra/error.h>
27 #include <vppinfra/types.h>
28 #include <vcl/vcom_glibc_socket.h>
30 #define MAX_VCOM_APP_NAME 256
32 /* Returns 0 on success or -1 on error. */
33 extern int vcom_set_app_name (char *__app_name);
37 * File descriptor based APIs
42 * vpp implementation of glibc APIs from <unistd.h>
44 extern int vcom_close (int __fd);
46 extern ssize_t __wur vcom_read (int __fd, void *__buf, size_t __nbytes);
48 extern ssize_t __wur vcom_write (int __fd, const void *__buf, size_t __n);
50 extern ssize_t __wur vcom_readv (int __fd, const struct iovec *__iov,
53 extern ssize_t __wur vcom_writev (int __fd, const struct iovec *__iov,
57 * vpp implementation of glibc APIs from <fcntl.h>
59 extern int vcom_fcntl (int __fd, int __cmd, ...);
62 * VPP implementation of glibc APIs ioctl
64 extern int vcom_ioctl (int __fd, unsigned long int __cmd, ...);
67 * vpp implementation of glibc APIs from <sys/select.h>
70 vcom_select (int __nfds, fd_set * __restrict __readfds,
71 fd_set * __restrict __writefds,
72 fd_set * __restrict __exceptfds,
73 struct timeval *__restrict __timeout);
77 vcom_pselect (int __nfds, fd_set * __restrict __readfds,
78 fd_set * __restrict __writefds,
79 fd_set * __restrict __exceptfds,
80 const struct timespec *__restrict __timeout,
81 const __sigset_t * __restrict __sigmask);
85 * vpp implementation of glibc APIs from <sys/socket.h>
87 extern int __THROW vcom_socket (int __domain, int __type, int __protocol);
89 /* On Linux, the only supported domain for this call is AF_UNIX
90 * (or synonymously, AF_LOCAL). Most implementations have the
92 * vpp does not implement AF_UNIX domain in this release.
95 vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]);
98 vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
101 vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
102 socklen_t * __restrict __len);
105 vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
108 vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
109 socklen_t * __restrict __len);
112 vcom_sendfile (int __out_fd, int __in_fd, off_t * __offset, int __len);
114 extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
117 vcom_sendto (int __fd, const void *__buf, size_t __n,
118 int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
121 vcom_recvfrom (int __fd, void *__restrict __buf,
122 size_t __n, int __flags,
123 __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
126 vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
130 sendmmsg (int __fd, struct mmsghdr *__vmessages,
131 unsigned int __vlen, int __flags);
134 extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
138 vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
139 unsigned int __vlen, int __flags, struct timespec *__tmo);
143 vcom_getsockopt (int __fd, int __level, int __optname,
144 void *__restrict __optval, socklen_t * __restrict __optlen);
147 vcom_setsockopt (int __fd, int __level, int __optname,
148 const void *__optval, socklen_t __optlen);
150 extern int __THROW vcom_listen (int __fd, int __n);
153 vcom_accept (int __fd, __SOCKADDR_ARG __addr,
154 socklen_t * __restrict __addr_len);
158 * Similar to 'accept' but takes an additional parameter to specify
161 /* TBD: implemented later */
163 vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
164 socklen_t * __restrict __addr_len, int __flags);
167 extern int __THROW vcom_shutdown (int __fd, int __how);
169 extern int __THROW vcom_epoll_create (int __size);
171 extern int __THROW vcom_epoll_create1 (int __flags);
174 vcom_epoll_ctl (int __epfd, int __op, int __fd, struct epoll_event *__event);
177 vcom_epoll_wait (int __epfd, struct epoll_event *__events,
178 int __maxevents, int __timeout);
181 vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
182 int __maxevents, int __timeout, const __sigset_t * __ss);
185 * NOTE: observed __nfds is less than 128 from kubecon strace files
186 * for the POC, it's fair to assume that nfds is less than 1024.
187 * TBD: make it thread safe and design to scale.
189 #define MAX_POLL_NFDS_DEFAULT 1024
190 extern int vcom_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
194 vcom_ppoll (struct pollfd *__fds, nfds_t __nfds,
195 const struct timespec *__timeout, const __sigset_t * __ss);
199 #endif /* included_vcom_h */
202 * fd.io coding-style-patch-verification: ON
205 * eval: (c-set-style "gnu")