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...
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)
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
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
42 #define ACE_SHUTDOWN_READ 0
43 #endif /* SD_RECEIVE */
46 #define ACE_SHUTDOWN_WRITE SD_SEND
47 #elif defined (SHUT_WR)
48 #define ACE_SHUTDOWN_WRITE SHUT_WR
50 #define ACE_SHUTDOWN_WRITE 1
54 #define ACE_SHUTDOWN_BOTH SD_BOTH
55 #elif defined (SHUT_RDWR)
56 #define ACE_SHUTDOWN_BOTH SHUT_RDWR
58 #define ACE_SHUTDOWN_BOTH 2
61 #if defined (IP_RECVDSTADDR)
62 #define ACE_RECVPKTINFO IP_RECVDSTADDR
63 #elif defined (IP_PKTINFO)
64 #define ACE_RECVPKTINFO IP_PKTINFO
67 #if defined (ACE_HAS_IPV6)
68 #if defined (IPV6_RECVPKTINFO)
69 #define ACE_RECVPKTINFO6 IPV6_RECVPKTINFO
73 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
75 class ACE_Accept_QoS_Params
;
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
,
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.
99 ACE_HANDLE
accept (ACE_HANDLE handle
,
100 struct sockaddr
*addr
,
102 const ACE_Accept_QoS_Params
&qos_params
);
104 ACE_NAMESPACE_INLINE_FUNCTION
105 int bind (ACE_HANDLE s
,
106 struct sockaddr
*name
,
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
,
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.
125 int connect (ACE_HANDLE handle
,
126 const sockaddr
*addr
,
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
,
142 ACE_NAMESPACE_INLINE_FUNCTION
143 int getsockname (ACE_HANDLE handle
,
144 struct sockaddr
*addr
,
146 ACE_NAMESPACE_INLINE_FUNCTION
147 int getsockopt (ACE_HANDLE handle
,
153 /// Joins a leaf node into a QoS-enabled multi-point session.
155 ACE_HANDLE
join_leaf (ACE_HANDLE socket
,
156 const sockaddr
*name
,
158 const ACE_QoS_Params
&qos_params
);
160 ACE_NAMESPACE_INLINE_FUNCTION
161 int listen (ACE_HANDLE handle
,
164 ACE_NAMESPACE_INLINE_FUNCTION
165 ssize_t
recv (ACE_HANDLE handle
,
170 ACE_NAMESPACE_INLINE_FUNCTION
171 ssize_t
recvfrom (ACE_HANDLE handle
,
175 struct sockaddr
*addr
,
178 ACE_NAMESPACE_INLINE_FUNCTION
179 ssize_t
recvfrom (ACE_HANDLE handle
,
182 size_t &number_of_bytes_recvd
,
184 struct sockaddr
*addr
,
186 ACE_OVERLAPPED
*overlapped
,
187 ACE_OVERLAPPED_COMPLETION_FUNC func
);
189 ACE_NAMESPACE_INLINE_FUNCTION
190 ssize_t
recvmsg (ACE_HANDLE handle
,
194 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
196 int recvmsg_win32_i (ACE_HANDLE handle
,
199 unsigned long &bytes_received
);
202 ACE_NAMESPACE_INLINE_FUNCTION
203 ssize_t
recvv (ACE_HANDLE handle
,
207 ACE_NAMESPACE_INLINE_FUNCTION
208 ssize_t
send (ACE_HANDLE handle
,
213 /// internal function used by send when an ENOBUFS condition
214 /// requires a buffer to do a partial send
216 ssize_t
send_partial_i (ACE_HANDLE handle
,
221 ACE_NAMESPACE_INLINE_FUNCTION
222 ssize_t
sendmsg (ACE_HANDLE handle
,
223 const struct msghdr
*msg
,
226 #if !defined ACE_LACKS_RECVMSG && defined ACE_HAS_WINSOCK2 && ACE_HAS_WINSOCK2
228 int sendmsg_win32_i (ACE_HANDLE handle
,
231 unsigned long &bytes_sent
);
234 ACE_NAMESPACE_INLINE_FUNCTION
235 ssize_t
sendto (ACE_HANDLE handle
,
239 const struct sockaddr
*addr
,
242 ACE_NAMESPACE_INLINE_FUNCTION
243 ssize_t
sendto (ACE_HANDLE handle
,
244 const iovec
*buffers
,
246 size_t &number_of_bytes_sent
,
248 const struct sockaddr
*addr
,
250 ACE_OVERLAPPED
*overlapped
,
251 ACE_OVERLAPPED_COMPLETION_FUNC func
);
253 ACE_NAMESPACE_INLINE_FUNCTION
254 ssize_t
sendv (ACE_HANDLE handle
,
258 /// internal function used by sendv when an ENOBUFS condition
259 /// requires a buffer to do a partial send
261 ssize_t
sendv_partial_i (ACE_HANDLE handle
,
265 /// Manipulate the options associated with a socket.
266 ACE_NAMESPACE_INLINE_FUNCTION
267 int setsockopt (ACE_HANDLE handle
,
273 ACE_NAMESPACE_INLINE_FUNCTION
274 int shutdown (ACE_HANDLE handle
,
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.
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).
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
,
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
,
311 ACE_Protocol_Info
*protocolinfo
,
315 ACE_NAMESPACE_INLINE_FUNCTION
316 int socketpair (int domain
,
321 } /* namespace ACE_OS */
323 ACE_END_VERSIONED_NAMESPACE_DECL
325 # if defined (ACE_HAS_INLINED_OSCALLS)
326 # if defined (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 */