vcom.h revision 20574915
1/*
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:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef included_vcom_h
17#define included_vcom_h
18
19/* VCOM DEBUG flag.  Setting this to 1 or 0 turns off
20   ASSERT & other debugging code. */
21#ifndef VCOM_DEBUG
22#define VCOM_DEBUG 0
23#endif
24
25#include <libvcl-ldpreload/vcom_glibc_socket.h>
26
27#define MAX_VCOM_APP_NAME  256
28
29/* Returns 0 on success or -1 on error. */
30extern int vcom_set_app_name (char *__app_name);
31
32/*
33 *
34 * File descriptor based APIs
35 *
36 */
37
38/*
39 * vpp implementation of glibc APIs from <unistd.h>
40 */
41extern int vcom_close (int __fd);
42
43extern ssize_t __wur vcom_read (int __fd, void *__buf, size_t __nbytes);
44
45extern ssize_t __wur vcom_write (int __fd, const void *__buf, size_t __n);
46
47extern ssize_t __wur vcom_readv (int __fd, const struct iovec * __iov, int __iovcnt);
48
49extern ssize_t __wur vcom_writev (int __fd, const struct iovec * __iov, int __iovcnt);
50
51/*
52 * vpp implementation of glibc APIs from <fcntl.h>
53 */
54extern int vcom_fcntl (int __fd, int __cmd, ...);
55
56/*
57 * vpp implementation of glibc APIs from <sys/select.h>
58 */
59extern int
60vcom_select (int __nfds, fd_set * __restrict __readfds,
61             fd_set * __restrict __writefds,
62             fd_set * __restrict __exceptfds,
63             struct timeval *__restrict __timeout);
64
65#ifdef __USE_XOPEN2K
66extern int
67vcom_pselect (int __nfds, fd_set * __restrict __readfds,
68              fd_set * __restrict __writefds,
69              fd_set * __restrict __exceptfds,
70              const struct timespec *__restrict __timeout,
71              const __sigset_t * __restrict __sigmask);
72#endif
73
74/*
75 * vpp implementation of glibc APIs from <sys/socket.h>
76 */
77extern int __THROW vcom_socket (int __domain, int __type, int __protocol);
78
79/* On Linux, the only supported domain for this call is AF_UNIX
80* (or synonymously, AF_LOCAL). Most implementations have the
81* same restriction.
82* vpp does not implement AF_UNIX domain in this release.
83* */
84extern int __THROW
85vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]);
86
87extern int __THROW
88vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
89
90extern int __THROW
91vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
92                  socklen_t * __restrict __len);
93
94extern int
95vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
96
97extern int __THROW
98vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
99                  socklen_t * __restrict __len);
100
101extern ssize_t
102vcom_send (int __fd, const void *__buf, size_t __n, int __flags);
103
104extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
105
106extern ssize_t
107vcom_sendto (int __fd, const void *__buf, size_t __n,
108             int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
109
110extern ssize_t
111vcom_recvfrom (int __fd, void *__restrict __buf,
112               size_t __n, int __flags,
113               __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
114
115extern ssize_t
116vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
117
118#ifdef __USE_GNU
119extern int
120sendmmsg (int __fd, struct mmsghdr *__vmessages,
121          unsigned int __vlen, int __flags);
122#endif
123
124extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
125
126#ifdef __USE_GNU
127extern int
128vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
129               unsigned int __vlen, int __flags, struct timespec *__tmo);
130#endif
131
132extern int __THROW
133vcom_getsockopt (int __fd, int __level, int __optname,
134                 void *__restrict __optval, socklen_t * __restrict __optlen);
135
136extern int __THROW
137vcom_setsockopt (int __fd, int __level, int __optname,
138                 const void *__optval, socklen_t __optlen);
139
140extern int __THROW vcom_listen (int __fd, int __n);
141
142extern int
143vcom_accept (int __fd, __SOCKADDR_ARG __addr,
144             socklen_t * __restrict __addr_len);
145
146#ifdef __USE_GNU
147/*
148 * Similar to 'accept' but takes an additional parameter to specify
149 * flags.
150 * */
151/* TBD: implemented later */
152extern int
153vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
154              socklen_t * __restrict __addr_len, int __flags);
155#endif
156
157extern int __THROW vcom_shutdown (int __fd, int __how);
158
159extern int __THROW
160vcom_epoll_create (int __size);
161
162extern int __THROW
163vcom_epoll_create1 (int __flags);
164
165extern int __THROW
166vcom_epoll_ctl (int __epfd, int __op, int __fd,
167                struct epoll_event *__event);
168
169extern int
170vcom_epoll_wait (int __epfd, struct epoll_event *__events,
171                 int __maxevents, int __timeout);
172
173extern int
174vcom_epoll_pwait (int __epfd, struct epoll_event *__events,
175                  int __maxevents, int __timeout,
176                  const __sigset_t *__ss);
177
178extern int
179vcom_poll (struct pollfd *__fds, nfds_t __nfds, int __timeout);
180
181#ifdef __USE_GNU
182extern int
183vcom_ppoll (struct pollfd *__fds, nfds_t __nfds,
184            const struct timespec *__timeout,
185            const __sigset_t *__ss);
186#endif
187
188
189#endif /* included_vcom_h */
190
191/*
192 * fd.io coding-style-patch-verification: ON
193 *
194 * Local Variables:
195 * eval: (c-set-style "gnu")
196 * End:
197 */
198