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