3 //=============================================================================
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 //=============================================================================
13 #ifndef ACE_OS_NS_SYS_SOCKET_H
14 # define ACE_OS_NS_SYS_SOCKET_H
16 # include /**/ "ace/pre.h"
18 # include "ace/config-all.h"
20 # if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/os_include/sys/os_socket.h"
25 #include "ace/os_include/net/os_if.h"
26 #include "ace/OS_NS_stropts.h"
27 #include /**/ "ace/ACE_export.h"
29 #if defined (ACE_EXPORT_MACRO)
30 # undef ACE_EXPORT_MACRO
32 #define ACE_EXPORT_MACRO ACE_Export
34 /// These are available values for the @a how argument to ACE_OS::shutdown().
35 #if defined (SD_RECEIVE)
36 #define ACE_SHUTDOWN_READ SD_RECEIVE
37 #elif defined (SHUT_RD)
38 #define ACE_SHUTDOWN_READ SHUT_RD
40 #define ACE_SHUTDOWN_READ 0
41 #endif /* SD_RECEIVE */
44 #define ACE_SHUTDOWN_WRITE SD_SEND
45 #elif defined (SHUT_WR)
46 #define ACE_SHUTDOWN_WRITE SHUT_WR
48 #define ACE_SHUTDOWN_WRITE 1
52 #define ACE_SHUTDOWN_BOTH SD_BOTH
53 #elif defined (SHUT_RDWR)
54 #define ACE_SHUTDOWN_BOTH SHUT_RDWR
56 #define ACE_SHUTDOWN_BOTH 2
59 #if defined (IP_RECVDSTADDR)
60 #define ACE_RECVPKTINFO IP_RECVDSTADDR
61 #elif defined (IP_PKTINFO)
62 #define ACE_RECVPKTINFO IP_PKTINFO
65 #if defined (ACE_HAS_IPV6)
66 #if defined (IPV6_RECVPKTINFO)
67 #define ACE_RECVPKTINFO6 IPV6_RECVPKTINFO
71 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
73 class ACE_Accept_QoS_Params
;
78 # if defined (ACE_WIN32)
79 /// Keeps track of whether we've already initialized WinSock...
80 extern ACE_Export
int socket_initialized_
;
81 # endif /* ACE_WIN32 */
83 //@{ @name A set of wrappers for sockets.
84 /// BSD-style @c accept (no QoS).
85 ACE_NAMESPACE_INLINE_FUNCTION
86 ACE_HANDLE
accept (ACE_HANDLE handle
,
87 struct sockaddr
*addr
,
91 * QoS-enabled @c accept, which passes @a qos_params to @c accept. If
92 * the OS platform doesn't support QoS-enabled @c accept then the
93 * @a qos_params are ignored and the BSD-style @c accept is called.
96 ACE_HANDLE
accept (ACE_HANDLE handle
,
97 struct sockaddr
*addr
,
99 const ACE_Accept_QoS_Params
&qos_params
);
101 ACE_NAMESPACE_INLINE_FUNCTION
102 int bind (ACE_HANDLE s
,
103 struct sockaddr
*name
,
106 /// Takes care of windows specific requirement to call closesocket
107 ACE_NAMESPACE_INLINE_FUNCTION
108 int closesocket (ACE_HANDLE s
);
110 /// BSD-style @c connect (no QoS).
111 ACE_NAMESPACE_INLINE_FUNCTION
112 int connect (ACE_HANDLE handle
,
113 struct sockaddr
*addr
,
117 * QoS-enabled @c connect, which passes @a qos_params to @c connect.
118 * If the OS platform doesn't support QoS-enabled @c connect then the
119 * @a qos_params are ignored and the BSD-style @c connect is called.
122 int connect (ACE_HANDLE handle
,
123 const sockaddr
*addr
,
125 const ACE_QoS_Params
&qos_params
);
127 /// Retrieve information about available transport protocols
128 /// installed on the local machine. Windows specific...
129 ACE_NAMESPACE_INLINE_FUNCTION
130 int enum_protocols (int *protocols
,
131 ACE_Protocol_Info
*protocol_buffer
,
132 u_long
*buffer_length
);
134 ACE_NAMESPACE_INLINE_FUNCTION
135 int getpeername (ACE_HANDLE handle
,
136 struct sockaddr
*addr
,
139 ACE_NAMESPACE_INLINE_FUNCTION
140 int getsockname (ACE_HANDLE handle
,
141 struct sockaddr
*addr
,
143 ACE_NAMESPACE_INLINE_FUNCTION
144 int getsockopt (ACE_HANDLE handle
,
150 /// Joins a leaf node into a QoS-enabled multi-point session.
152 ACE_HANDLE
join_leaf (ACE_HANDLE socket
,
153 const sockaddr
*name
,
155 const ACE_QoS_Params
&qos_params
);
157 ACE_NAMESPACE_INLINE_FUNCTION
158 int listen (ACE_HANDLE handle
,
161 ACE_NAMESPACE_INLINE_FUNCTION
162 ssize_t
recv (ACE_HANDLE handle
,
167 ACE_NAMESPACE_INLINE_FUNCTION
168 ssize_t
recvfrom (ACE_HANDLE handle
,
172 struct sockaddr
*addr
,
175 ACE_NAMESPACE_INLINE_FUNCTION
176 ssize_t
recvfrom (ACE_HANDLE handle
,
179 size_t &number_of_bytes_recvd
,
181 struct sockaddr
*addr
,
183 ACE_OVERLAPPED
*overlapped
,
184 ACE_OVERLAPPED_COMPLETION_FUNC func
);
186 ACE_NAMESPACE_INLINE_FUNCTION
187 ssize_t
recvmsg (ACE_HANDLE handle
,
191 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
193 int recvmsg_win32_i (ACE_HANDLE handle
,
196 unsigned long &bytes_received
);
199 ACE_NAMESPACE_INLINE_FUNCTION
200 ssize_t
recvv (ACE_HANDLE handle
,
204 ACE_NAMESPACE_INLINE_FUNCTION
205 ssize_t
send (ACE_HANDLE handle
,
210 /// internal function used by send when an ENOBUFS condition
211 /// requires a buffer to do a partial send
213 ssize_t
send_partial_i (ACE_HANDLE handle
,
218 ACE_NAMESPACE_INLINE_FUNCTION
219 ssize_t
sendmsg (ACE_HANDLE handle
,
220 const struct msghdr
*msg
,
223 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
225 int sendmsg_win32_i (ACE_HANDLE handle
,
228 unsigned long &bytes_sent
);
231 ACE_NAMESPACE_INLINE_FUNCTION
232 ssize_t
sendto (ACE_HANDLE handle
,
236 const struct sockaddr
*addr
,
239 ACE_NAMESPACE_INLINE_FUNCTION
240 ssize_t
sendto (ACE_HANDLE handle
,
241 const iovec
*buffers
,
243 size_t &number_of_bytes_sent
,
245 const struct sockaddr
*addr
,
247 ACE_OVERLAPPED
*overlapped
,
248 ACE_OVERLAPPED_COMPLETION_FUNC func
);
250 ACE_NAMESPACE_INLINE_FUNCTION
251 ssize_t
sendv (ACE_HANDLE handle
,
255 /// internal function used by sendv when an ENOBUFS condition
256 /// requires a buffer to do a partial send
258 ssize_t
sendv_partial_i (ACE_HANDLE handle
,
262 /// Manipulate the options associated with a socket.
263 ACE_NAMESPACE_INLINE_FUNCTION
264 int setsockopt (ACE_HANDLE handle
,
270 ACE_NAMESPACE_INLINE_FUNCTION
271 int shutdown (ACE_HANDLE handle
,
274 ACE_NAMESPACE_INLINE_FUNCTION
275 unsigned int if_nametoindex (const char *ifname
);
277 ACE_NAMESPACE_INLINE_FUNCTION
278 char *if_indextoname (unsigned int ifindex
, char *ifname
);
280 ACE_NAMESPACE_INLINE_FUNCTION
281 struct if_nameindex
*if_nameindex ();
283 ACE_NAMESPACE_INLINE_FUNCTION
284 void if_freenameindex (struct if_nameindex
*ptr
);
286 /// Initialize WinSock before first use (e.g., when a DLL is first
287 /// loaded or the first use of a socket() call.
289 int socket_init (int version_high
= 1,
290 int version_low
= 1);
292 /// Finalize WinSock after last use (e.g., when a DLL is unloaded).
296 /// Create a BSD-style socket (no QoS).
297 ACE_NAMESPACE_INLINE_FUNCTION
298 ACE_HANDLE
socket (int protocol_family
,
302 /// Create a QoS-enabled socket. If the OS platform doesn't support
303 /// QoS-enabled <socket> then the BSD-style <socket> is called.
304 ACE_NAMESPACE_INLINE_FUNCTION
305 ACE_HANDLE
socket (int protocol_family
,
308 ACE_Protocol_Info
*protocolinfo
,
312 ACE_NAMESPACE_INLINE_FUNCTION
313 int socketpair (int domain
,
317 } /* namespace ACE_OS */
319 ACE_END_VERSIONED_NAMESPACE_DECL
321 # if defined (ACE_HAS_INLINED_OSCALLS)
322 # if defined (ACE_INLINE)
324 # endif /* ACE_INLINE */
325 # define ACE_INLINE inline
326 # include "ace/OS_NS_sys_socket.inl"
327 # endif /* ACE_HAS_INLINED_OSCALLS */
329 # include /**/ "ace/post.h"
330 #endif /* ACE_OS_NS_SYS_SOCKET_H */