GitHub Actions: Try MSVC builds with /std:c++17 and 20
[ACE_TAO.git] / ACE / ace / OS_NS_sys_socket.h
blobfaa6cd9bdfb66bc91f14f89ec1f8addeea2cabd8
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_NS_sys_socket.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 * Originally in OS.h.
13 //=============================================================================
15 #ifndef ACE_OS_NS_SYS_SOCKET_H
16 # define ACE_OS_NS_SYS_SOCKET_H
18 # include /**/ "ace/pre.h"
20 # include "ace/config-all.h"
22 # if !defined (ACE_LACKS_PRAGMA_ONCE)
23 # pragma once
24 # endif /* ACE_LACKS_PRAGMA_ONCE */
26 #include "ace/os_include/sys/os_socket.h"
27 #include "ace/os_include/net/os_if.h"
28 #include "ace/OS_NS_stropts.h"
29 #include /**/ "ace/ACE_export.h"
31 #if defined (ACE_EXPORT_MACRO)
32 # undef ACE_EXPORT_MACRO
33 #endif
34 #define ACE_EXPORT_MACRO ACE_Export
36 /// These are available values for the @a how argument to ACE_OS::shutdown().
37 #if defined (SD_RECEIVE)
38 #define ACE_SHUTDOWN_READ SD_RECEIVE
39 #elif defined (SHUT_RD)
40 #define ACE_SHUTDOWN_READ SHUT_RD
41 #else
42 #define ACE_SHUTDOWN_READ 0
43 #endif /* SD_RECEIVE */
45 #if defined (SD_SEND)
46 #define ACE_SHUTDOWN_WRITE SD_SEND
47 #elif defined (SHUT_WR)
48 #define ACE_SHUTDOWN_WRITE SHUT_WR
49 #else
50 #define ACE_SHUTDOWN_WRITE 1
51 #endif /* SD_SEND */
53 #if defined (SD_BOTH)
54 #define ACE_SHUTDOWN_BOTH SD_BOTH
55 #elif defined (SHUT_RDWR)
56 #define ACE_SHUTDOWN_BOTH SHUT_RDWR
57 #else
58 #define ACE_SHUTDOWN_BOTH 2
59 #endif /* SD_BOTH */
61 #if defined (IP_RECVDSTADDR)
62 #define ACE_RECVPKTINFO IP_RECVDSTADDR
63 #elif defined (IP_PKTINFO)
64 #define ACE_RECVPKTINFO IP_PKTINFO
65 #endif
67 #if defined (ACE_HAS_IPV6)
68 #if defined (IPV6_RECVPKTINFO)
69 #define ACE_RECVPKTINFO6 IPV6_RECVPKTINFO
70 #endif
71 #endif
73 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
75 class ACE_Accept_QoS_Params;
76 class ACE_QoS_Params;
78 namespace ACE_OS
81 # if defined (ACE_WIN32)
82 /// Keeps track of whether we've already initialized WinSock...
83 extern ACE_Export int socket_initialized_;
84 # endif /* ACE_WIN32 */
86 //@{ @name A set of wrappers for sockets.
87 /// BSD-style @c accept (no QoS).
88 ACE_NAMESPACE_INLINE_FUNCTION
89 ACE_HANDLE accept (ACE_HANDLE handle,
90 struct sockaddr *addr,
91 int *addrlen);
93 /**
94 * QoS-enabled @c accept, which passes @a qos_params to @c accept. If
95 * the OS platform doesn't support QoS-enabled @c accept then the
96 * @a qos_params are ignored and the BSD-style @c accept is called.
98 extern ACE_Export
99 ACE_HANDLE accept (ACE_HANDLE handle,
100 struct sockaddr *addr,
101 int *addrlen,
102 const ACE_Accept_QoS_Params &qos_params);
104 ACE_NAMESPACE_INLINE_FUNCTION
105 int bind (ACE_HANDLE s,
106 struct sockaddr *name,
107 int namelen);
109 /// Takes care of windows specific requirement to call closesocket
110 ACE_NAMESPACE_INLINE_FUNCTION
111 int closesocket (ACE_HANDLE s);
113 /// BSD-style @c connect (no QoS).
114 ACE_NAMESPACE_INLINE_FUNCTION
115 int connect (ACE_HANDLE handle,
116 struct sockaddr *addr,
117 int addrlen);
120 * QoS-enabled @c connect, which passes @a qos_params to @c connect.
121 * If the OS platform doesn't support QoS-enabled @c connect then the
122 * @a qos_params are ignored and the BSD-style @c connect is called.
124 extern ACE_Export
125 int connect (ACE_HANDLE handle,
126 const sockaddr *addr,
127 int addrlen,
128 const ACE_QoS_Params &qos_params);
130 /// Retrieve information about available transport protocols
131 /// installed on the local machine. Windows specific...
132 ACE_NAMESPACE_INLINE_FUNCTION
133 int enum_protocols (int *protocols,
134 ACE_Protocol_Info *protocol_buffer,
135 u_long *buffer_length);
137 ACE_NAMESPACE_INLINE_FUNCTION
138 int getpeername (ACE_HANDLE handle,
139 struct sockaddr *addr,
140 int *addrlen);
142 ACE_NAMESPACE_INLINE_FUNCTION
143 int getsockname (ACE_HANDLE handle,
144 struct sockaddr *addr,
145 int *addrlen);
146 ACE_NAMESPACE_INLINE_FUNCTION
147 int getsockopt (ACE_HANDLE handle,
148 int level,
149 int optname,
150 char *optval,
151 int *optlen);
153 /// Joins a leaf node into a QoS-enabled multi-point session.
154 extern ACE_Export
155 ACE_HANDLE join_leaf (ACE_HANDLE socket,
156 const sockaddr *name,
157 int namelen,
158 const ACE_QoS_Params &qos_params);
160 ACE_NAMESPACE_INLINE_FUNCTION
161 int listen (ACE_HANDLE handle,
162 int backlog);
164 ACE_NAMESPACE_INLINE_FUNCTION
165 ssize_t recv (ACE_HANDLE handle,
166 char *buf,
167 size_t len,
168 int flags = 0);
170 ACE_NAMESPACE_INLINE_FUNCTION
171 ssize_t recvfrom (ACE_HANDLE handle,
172 char *buf,
173 size_t len,
174 int flags,
175 struct sockaddr *addr,
176 int *addrlen);
178 ACE_NAMESPACE_INLINE_FUNCTION
179 ssize_t recvfrom (ACE_HANDLE handle,
180 iovec *buffers,
181 int buffer_count,
182 size_t &number_of_bytes_recvd,
183 int &flags,
184 struct sockaddr *addr,
185 int *addrlen,
186 ACE_OVERLAPPED *overlapped,
187 ACE_OVERLAPPED_COMPLETION_FUNC func);
189 ACE_NAMESPACE_INLINE_FUNCTION
190 ssize_t recvmsg (ACE_HANDLE handle,
191 struct msghdr *msg,
192 int flags);
194 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
195 extern ACE_Export
196 int recvmsg_win32_i (ACE_HANDLE handle,
197 msghdr *msg,
198 int flags,
199 unsigned long &bytes_received);
200 #endif
202 ACE_NAMESPACE_INLINE_FUNCTION
203 ssize_t recvv (ACE_HANDLE handle,
204 iovec *iov,
205 int iovlen);
207 ACE_NAMESPACE_INLINE_FUNCTION
208 ssize_t send (ACE_HANDLE handle,
209 const char *buf,
210 size_t len,
211 int flags = 0);
213 /// internal function used by send when an ENOBUFS condition
214 /// requires a buffer to do a partial send
215 extern ACE_Export
216 ssize_t send_partial_i (ACE_HANDLE handle,
217 const char *buf,
218 size_t len,
219 int flags);
221 ACE_NAMESPACE_INLINE_FUNCTION
222 ssize_t sendmsg (ACE_HANDLE handle,
223 const struct msghdr *msg,
224 int flags);
226 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
227 extern ACE_Export
228 int sendmsg_win32_i (ACE_HANDLE handle,
229 msghdr const *msg,
230 int flags,
231 unsigned long &bytes_sent);
232 #endif
234 ACE_NAMESPACE_INLINE_FUNCTION
235 ssize_t sendto (ACE_HANDLE handle,
236 const char *buf,
237 size_t len,
238 int flags,
239 const struct sockaddr *addr,
240 int addrlen);
242 ACE_NAMESPACE_INLINE_FUNCTION
243 ssize_t sendto (ACE_HANDLE handle,
244 const iovec *buffers,
245 int buffer_count,
246 size_t &number_of_bytes_sent,
247 int flags,
248 const struct sockaddr *addr,
249 int addrlen,
250 ACE_OVERLAPPED *overlapped,
251 ACE_OVERLAPPED_COMPLETION_FUNC func);
253 ACE_NAMESPACE_INLINE_FUNCTION
254 ssize_t sendv (ACE_HANDLE handle,
255 const iovec *iov,
256 int iovcnt);
258 /// internal function used by sendv when an ENOBUFS condition
259 /// requires a buffer to do a partial send
260 extern ACE_Export
261 ssize_t sendv_partial_i (ACE_HANDLE handle,
262 const iovec *iov,
263 int iovcnt);
265 /// Manipulate the options associated with a socket.
266 ACE_NAMESPACE_INLINE_FUNCTION
267 int setsockopt (ACE_HANDLE handle,
268 int level,
269 int optname,
270 const char *optval,
271 int optlen);
273 ACE_NAMESPACE_INLINE_FUNCTION
274 int shutdown (ACE_HANDLE handle,
275 int how);
277 ACE_NAMESPACE_INLINE_FUNCTION
278 unsigned int if_nametoindex (const char *ifname);
280 ACE_NAMESPACE_INLINE_FUNCTION
281 char *if_indextoname (unsigned int ifindex, char *ifname);
283 ACE_NAMESPACE_INLINE_FUNCTION
284 struct if_nameindex *if_nameindex (void);
286 ACE_NAMESPACE_INLINE_FUNCTION
287 void if_freenameindex (struct if_nameindex *ptr);
289 /// Initialize WinSock before first use (e.g., when a DLL is first
290 /// loaded or the first use of a socket() call.
291 extern ACE_Export
292 int socket_init (int version_high = 1,
293 int version_low = 1);
295 /// Finalize WinSock after last use (e.g., when a DLL is unloaded).
296 extern ACE_Export
297 int socket_fini (void);
299 /// Create a BSD-style socket (no QoS).
300 ACE_NAMESPACE_INLINE_FUNCTION
301 ACE_HANDLE socket (int protocol_family,
302 int type,
303 int proto);
305 /// Create a QoS-enabled socket. If the OS platform doesn't support
306 /// QoS-enabled <socket> then the BSD-style <socket> is called.
307 ACE_NAMESPACE_INLINE_FUNCTION
308 ACE_HANDLE socket (int protocol_family,
309 int type,
310 int proto,
311 ACE_Protocol_Info *protocolinfo,
312 ACE_SOCK_GROUP g,
313 u_long flags);
315 ACE_NAMESPACE_INLINE_FUNCTION
316 int socketpair (int domain,
317 int type,
318 int protocol,
319 ACE_HANDLE sv[2]);
321 } /* namespace ACE_OS */
323 ACE_END_VERSIONED_NAMESPACE_DECL
325 # if defined (ACE_HAS_INLINED_OSCALLS)
326 # if defined (ACE_INLINE)
327 # undef ACE_INLINE
328 # endif /* ACE_INLINE */
329 # define ACE_INLINE inline
330 # include "ace/OS_NS_sys_socket.inl"
331 # endif /* ACE_HAS_INLINED_OSCALLS */
333 # include /**/ "ace/post.h"
334 #endif /* ACE_OS_NS_SYS_SOCKET_H */