vcom.h revision e1b749ab
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
47/*
48 * vpp implementation of glibc APIs from <fcntl.h>
49 */
50extern int vcom_fcntl (int __fd, int __cmd, ...);
51
52/*
53 * vpp implementation of glibc APIs from <sys/select.h>
54 */
55extern int
56vcom_select (int __nfds, fd_set * __restrict __readfds,
57	     fd_set * __restrict __writefds,
58	     fd_set * __restrict __exceptfds,
59	     struct timeval *__restrict __timeout);
60
61#ifdef __USE_XOPEN2K
62extern int
63vcom_pselect (int __nfds, fd_set * __restrict __readfds,
64	      fd_set * __restrict __writefds,
65	      fd_set * __restrict __exceptfds,
66	      const struct timespec *__restrict __timeout,
67	      const __sigset_t * __restrict __sigmask);
68#endif
69
70/*
71 * vpp implementation of glibc APIs from <sys/socket.h>
72 */
73extern int __THROW vcom_socket (int __domain, int __type, int __protocol);
74
75/* On Linux, the only supported domain for this call is AF_UNIX
76* (or synonymously, AF_LOCAL). Most implementations have the
77* same restriction.
78* vpp does not implement AF_UNIX domain in this release.
79* */
80extern int __THROW
81vcom_socketpair (int __domain, int __type, int __protocol, int __fds[2]);
82
83extern int __THROW
84vcom_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
85
86extern int __THROW
87vcom_getsockname (int __fd, __SOCKADDR_ARG __addr,
88		  socklen_t * __restrict __len);
89
90extern int
91vcom_connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
92
93extern int __THROW
94vcom_getpeername (int __fd, __SOCKADDR_ARG __addr,
95		  socklen_t * __restrict __len);
96
97extern ssize_t
98vcom_send (int __fd, const void *__buf, size_t __n, int __flags);
99
100extern ssize_t vcom_recv (int __fd, void *__buf, size_t __n, int __flags);
101
102extern ssize_t
103vcom_sendto (int __fd, const void *__buf, size_t __n,
104	     int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
105
106extern ssize_t
107vcom_recvfrom (int __fd, void *__restrict __buf,
108	       size_t __n, int __flags,
109	       __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
110
111extern ssize_t
112vcom_sendmsg (int __fd, const struct msghdr *__message, int __flags);
113
114#ifdef __USE_GNU
115extern int
116sendmmsg (int __fd, struct mmsghdr *__vmessages,
117	  unsigned int __vlen, int __flags);
118#endif
119
120extern ssize_t vcom_recvmsg (int __fd, struct msghdr *__message, int __flags);
121
122#ifdef __USE_GNU
123extern int
124vcom_recvmmsg (int __fd, struct mmsghdr *__vmessages,
125	       unsigned int __vlen, int __flags, struct timespec *__tmo);
126#endif
127
128extern int __THROW
129vcom_getsockopt (int __fd, int __level, int __optname,
130		 void *__restrict __optval, socklen_t * __restrict __optlen);
131
132extern int __THROW
133vcom_setsockopt (int __fd, int __level, int __optname,
134		 const void *__optval, socklen_t __optlen);
135
136extern int __THROW vcom_listen (int __fd, int __n);
137
138extern int
139vcom_accept (int __fd, __SOCKADDR_ARG __addr,
140	     socklen_t * __restrict __addr_len);
141
142#ifdef __USE_GNU
143/*
144 * Similar to 'accept' but takes an additional parameter to specify
145 * flags.
146 * */
147/* TBD: implemented later */
148extern int
149vcom_accept4 (int __fd, __SOCKADDR_ARG __addr,
150	      socklen_t * __restrict __addr_len, int __flags);
151#endif
152
153extern int __THROW vcom_shutdown (int __fd, int __how);
154
155#endif /* included_vcom_h */
156
157/*
158 * fd.io coding-style-patch-verification: ON
159 *
160 * Local Variables:
161 * eval: (c-set-style "gnu")
162 * End:
163 */
164