vcom_glibc_socket.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_glibc_socket_h
17#define included_vcom_glibc_socket_h
18
19#include <sys/types.h>
20#include <sys/socket.h>
21#include <sys/select.h>
22#include <arpa/inet.h>
23#include <fcntl.h>
24
25/*
26 *
27 * Generic glibc fd api
28 *
29 */
30/*
31 * glibc APIs from <unistd.h>
32 */
33
34/* Close the file descriptor FD.
35
36   This function is a cancellation point and therefore not marked with
37   __THROW.  */
38extern int close (int __fd);
39
40/* Read NBYTES into BUF from FD.  Return the
41   number read, -1 for errors or 0 for EOF.
42
43   This function is a cancellation point and therefore not marked with
44   __THROW.  */
45extern ssize_t __wur read (int __fd, void *__buf, size_t __nbytes);
46
47/* Write N bytes of BUF to FD.  Return the number written, or -1.
48
49   This function is a cancellation point and therefore not marked with
50   __THROW.  */
51extern ssize_t __wur write (int __fd, const void *__buf, size_t __n);
52
53
54/*
55 * glibc APIs from <fcntl.h>
56 */
57
58/* Do the file control operation described by CMD on FD.
59   The remaining arguments are interpreted depending on CMD.
60
61   This function is a cancellation point and therefore not marked with
62   __THROW.  */
63extern int fcntl (int __fd, int __cmd, ...);
64
65
66/*
67 * glibc APIs from <sys/select.h>
68 */
69
70/* Check the first NFDS descriptors each in READFDS (if not NULL) for read
71   readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
72   (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out
73   after waiting the interval specified therein.  Returns the number of ready
74   descriptors, or -1 for errors.
75
76
77   This function is a cancellation point and therefore not marked with
78   __THROW.  */
79extern int
80select (int __nfds, fd_set * __restrict __readfds,
81	fd_set * __restrict __writefds,
82	fd_set * __restrict __exceptfds,
83	struct timeval *__restrict __timeout);
84
85#ifdef __USE_XOPEN2K
86/* Same as above only that the TIMEOUT value is given with higher
87   resolution and a sigmask which is been set temporarily.  This version
88   should be used.
89
90   This function is a cancellation point and therefore not marked with
91   __THROW.  */
92extern int
93pselect (int __nfds, fd_set * __restrict __readfds,
94	 fd_set * __restrict __writefds,
95	 fd_set * __restrict __exceptfds,
96	 const struct timespec *__restrict __timeout,
97	 const __sigset_t * __restrict __sigmask);
98#endif
99
100
101/*
102 *
103 * Socket specific glibc api
104 *
105 */
106
107/*
108 * glibc APIs from <sys/socket.h>
109 */
110
111/* Create a new socket of type TYPE in domain DOMAIN, using
112   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
113   Returns a file descriptor for the new socket, or -1 for errors.  */
114extern int __THROW socket (int __domain, int __type, int __protocol);
115
116/* Create two new sockets, of type TYPE in domain DOMAIN and using
117   protocol PROTOCOL, which are connected to each other, and put file
118   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
119   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
120extern int __THROW
121socketpair (int __domain, int __type, int __protocol, int __fds[2]);
122
123/* Give the socket FD the local address ADDR (which is LEN bytes long).  */
124extern int __THROW
125bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
126
127/* Put the local address of FD into *ADDR and its length in *LEN.  */
128extern int __THROW
129getsockname (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len);
130
131/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
132   For connectionless socket types, just set the default address to send to
133   and the only address from which to accept transmissions.
134   Return 0 on success, -1 for errors.
135
136   This function is a cancellation point and therefore not marked with
137   __THROW.  */
138extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
139
140/* Put the address of the peer connected to socket FD into *ADDR
141   (which is *LEN bytes long), and its actual length into *LEN.  */
142extern int __THROW
143getpeername (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __len);
144
145/* Send N bytes of BUF to socket FD.  Returns the number sent or -1.
146
147   This function is a cancellation point and therefore not marked with
148   __THROW.  */
149extern ssize_t send (int __fd, const void *__buf, size_t __n, int __flags);
150
151/* Read N bytes into BUF from socket FD.
152   Returns the number read or -1 for errors.
153
154   This function is a cancellation point and therefore not marked with
155   __THROW.  */
156extern ssize_t recv (int __fd, void *__buf, size_t __n, int __flags);
157
158/* Send N bytes of BUF on socket FD to peer at address ADDR (which is
159   ADDR_LEN bytes long).  Returns the number sent, or -1 for errors.
160
161   This function is a cancellation point and therefore not marked with
162   __THROW.  */
163extern ssize_t
164sendto (int __fd, const void *__buf, size_t __n,
165	int __flags, __CONST_SOCKADDR_ARG __addr, socklen_t __addr_len);
166
167/* Read N bytes into BUF through socket FD.
168   If ADDR is not NULL, fill in *ADDR_LEN bytes of it with tha address of
169   the sender, and store the actual size of the address in *ADDR_LEN.
170   Returns the number of bytes read or -1 for errors.
171
172   This function is a cancellation point and therefore not marked with
173   __THROW.  */
174extern ssize_t
175recvfrom (int __fd, void *__restrict __buf,
176	  size_t __n, int __flags,
177	  __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
178
179/* Send a message described MESSAGE on socket FD.
180   Returns the number of bytes sent, or -1 for errors.
181
182   This function is a cancellation point and therefore not marked with
183   __THROW.  */
184extern ssize_t
185sendmsg (int __fd, const struct msghdr *__message, int __flags);
186
187#ifdef __USE_GNU
188/* Send a VLEN messages as described by VMESSAGES to socket FD.
189   Returns the number of datagrams successfully written or -1 for errors.
190
191   This function is a cancellation point and therefore not marked with
192   __THROW.  */
193extern int
194sendmmsg (int __fd, struct mmsghdr *__vmessages,
195	  unsigned int __vlen, int __flags);
196#endif
197
198/* Receive a message as described by MESSAGE from socket FD.
199   Returns the number of bytes read or -1 for errors.
200
201   This function is a cancellation point and therefore not marked with
202   __THROW.  */
203extern ssize_t recvmsg (int __fd, struct msghdr *__message, int __flags);
204
205#ifdef __USE_GNU
206/* Receive up to VLEN messages as described by VMESSAGES from socket FD.
207   Returns the number of messages received or -1 for errors.
208
209   This function is a cancellation point and therefore not marked with
210   __THROW.  */
211extern int
212recvmmsg (int __fd, struct mmsghdr *__vmessages,
213	  unsigned int __vlen, int __flags, struct timespec *__tmo);
214#endif
215
216
217/* Put the current value for socket FD's option OPTNAME at protocol level LEVEL
218   into OPTVAL (which is *OPTLEN bytes long), and set *OPTLEN to the value's
219   actual length.  Returns 0 on success, -1 for errors.  */
220extern int __THROW
221getsockopt (int __fd, int __level, int __optname,
222	    void *__restrict __optval, socklen_t * __restrict __optlen);
223
224/* Set socket FD's option OPTNAME at protocol level LEVEL
225   to *OPTVAL (which is OPTLEN bytes long).
226   Returns 0 on success, -1 for errors.  */
227extern int __THROW
228setsockopt (int __fd, int __level, int __optname,
229	    const void *__optval, socklen_t __optlen);
230
231/* Prepare to accept connections on socket FD.
232   N connection requests will be queued before further requests are refused.
233   Returns 0 on success, -1 for errors.  */
234extern int __THROW listen (int __fd, int __n);
235
236/* Await a connection on socket FD.
237   When a connection arrives, open a new socket to communicate with it,
238   set *ADDR (which is *ADDR_LEN bytes long) to the address of the connecting
239   peer and *ADDR_LEN to the address's actual length, and return the
240   new socket's descriptor, or -1 for errors.
241
242   This function is a cancellation point and therefore not marked with
243   __THROW.  */
244extern int
245accept (int __fd, __SOCKADDR_ARG __addr, socklen_t * __restrict __addr_len);
246
247#ifdef __USE_GNU
248/* Similar to 'accept' but takes an additional parameter to specify flags.
249
250   This function is a cancellation point and therefore not marked with
251   __THROW.  */
252     /* TBD: implemented later */
253extern int
254accept4 (int __fd, __SOCKADDR_ARG __addr,
255	 socklen_t * __restrict __addr_len, int __flags);
256#endif
257
258/* Shut down all or part of the connection open on socket FD.
259   HOW determines what to shut down:
260     SHUT_RD   = No more receptions;
261     SHUT_WR   = No more transmissions;
262     SHUT_RDWR = No more receptions or transmissions.
263   Returns 0 on success, -1 for errors.  */
264extern int __THROW shutdown (int __fd, int __how);
265
266#endif /* included_vcom_glibc_socket_h */
267
268/*
269 * fd.io coding-style-patch-verification: ON
270 *
271 * Local Variables:
272 * eval: (c-set-style "gnu")
273 * End:
274 */
275