04a28ef9e193983ee51818ef34a951162ebf73e7
[platform/upstream/boost.git] / boost / asio / detail / socket_ops.hpp
1 //
2 // detail/socket_ops.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_DETAIL_SOCKET_OPS_HPP
12 #define BOOST_ASIO_DETAIL_SOCKET_OPS_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #include <boost/system/error_code.hpp>
21 #include <boost/asio/detail/shared_ptr.hpp>
22 #include <boost/asio/detail/socket_types.hpp>
23 #include <boost/asio/detail/weak_ptr.hpp>
24
25 #include <boost/asio/detail/push_options.hpp>
26
27 namespace boost {
28 namespace asio {
29 namespace detail {
30 namespace socket_ops {
31
32 // Socket state bits.
33 enum
34 {
35   // The user wants a non-blocking socket.
36   user_set_non_blocking = 1,
37
38   // The socket has been set non-blocking.
39   internal_non_blocking = 2,
40
41   // Helper "state" used to determine whether the socket is non-blocking.
42   non_blocking = user_set_non_blocking | internal_non_blocking,
43
44   // User wants connection_aborted errors, which are disabled by default.
45   enable_connection_aborted = 4,
46
47   // The user set the linger option. Needs to be checked when closing.
48   user_set_linger = 8,
49
50   // The socket is stream-oriented.
51   stream_oriented = 16,
52
53   // The socket is datagram-oriented.
54   datagram_oriented = 32,
55
56   // The socket may have been dup()-ed.
57   possible_dup = 64
58 };
59
60 typedef unsigned char state_type;
61
62 struct noop_deleter { void operator()(void*) {} };
63 typedef shared_ptr<void> shared_cancel_token_type;
64 typedef weak_ptr<void> weak_cancel_token_type;
65
66 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
67
68 BOOST_ASIO_DECL socket_type accept(socket_type s, socket_addr_type* addr,
69     std::size_t* addrlen, boost::system::error_code& ec);
70
71 BOOST_ASIO_DECL socket_type sync_accept(socket_type s,
72     state_type state, socket_addr_type* addr,
73     std::size_t* addrlen, boost::system::error_code& ec);
74
75 #if defined(BOOST_ASIO_HAS_IOCP)
76
77 BOOST_ASIO_DECL void complete_iocp_accept(socket_type s,
78     void* output_buffer, DWORD address_length,
79     socket_addr_type* addr, std::size_t* addrlen,
80     socket_type new_socket, boost::system::error_code& ec);
81
82 #else // defined(BOOST_ASIO_HAS_IOCP)
83
84 BOOST_ASIO_DECL bool non_blocking_accept(socket_type s,
85     state_type state, socket_addr_type* addr, std::size_t* addrlen,
86     boost::system::error_code& ec, socket_type& new_socket);
87
88 #endif // defined(BOOST_ASIO_HAS_IOCP)
89
90 BOOST_ASIO_DECL int bind(socket_type s, const socket_addr_type* addr,
91     std::size_t addrlen, boost::system::error_code& ec);
92
93 BOOST_ASIO_DECL int close(socket_type s, state_type& state,
94     bool destruction, boost::system::error_code& ec);
95
96 BOOST_ASIO_DECL bool set_user_non_blocking(socket_type s,
97     state_type& state, bool value, boost::system::error_code& ec);
98
99 BOOST_ASIO_DECL bool set_internal_non_blocking(socket_type s,
100     state_type& state, bool value, boost::system::error_code& ec);
101
102 BOOST_ASIO_DECL int shutdown(socket_type s,
103     int what, boost::system::error_code& ec);
104
105 BOOST_ASIO_DECL int connect(socket_type s, const socket_addr_type* addr,
106     std::size_t addrlen, boost::system::error_code& ec);
107
108 BOOST_ASIO_DECL void sync_connect(socket_type s, const socket_addr_type* addr,
109     std::size_t addrlen, boost::system::error_code& ec);
110
111 #if defined(BOOST_ASIO_HAS_IOCP)
112
113 BOOST_ASIO_DECL void complete_iocp_connect(socket_type s,
114     boost::system::error_code& ec);
115
116 #endif // defined(BOOST_ASIO_HAS_IOCP)
117
118 BOOST_ASIO_DECL bool non_blocking_connect(socket_type s,
119     boost::system::error_code& ec);
120
121 BOOST_ASIO_DECL int socketpair(int af, int type, int protocol,
122     socket_type sv[2], boost::system::error_code& ec);
123
124 BOOST_ASIO_DECL bool sockatmark(socket_type s, boost::system::error_code& ec);
125
126 BOOST_ASIO_DECL size_t available(socket_type s, boost::system::error_code& ec);
127
128 BOOST_ASIO_DECL int listen(socket_type s,
129     int backlog, boost::system::error_code& ec);
130
131 #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
132 typedef WSABUF buf;
133 #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
134 typedef iovec buf;
135 #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
136
137 BOOST_ASIO_DECL void init_buf(buf& b, void* data, size_t size);
138
139 BOOST_ASIO_DECL void init_buf(buf& b, const void* data, size_t size);
140
141 BOOST_ASIO_DECL signed_size_type recv(socket_type s, buf* bufs,
142     size_t count, int flags, boost::system::error_code& ec);
143
144 BOOST_ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs,
145     size_t count, int flags, bool all_empty, boost::system::error_code& ec);
146
147 #if defined(BOOST_ASIO_HAS_IOCP)
148
149 BOOST_ASIO_DECL void complete_iocp_recv(state_type state,
150     const weak_cancel_token_type& cancel_token, bool all_empty,
151     boost::system::error_code& ec, size_t bytes_transferred);
152
153 #else // defined(BOOST_ASIO_HAS_IOCP)
154
155 BOOST_ASIO_DECL bool non_blocking_recv(socket_type s,
156     buf* bufs, size_t count, int flags, bool is_stream,
157     boost::system::error_code& ec, size_t& bytes_transferred);
158
159 #endif // defined(BOOST_ASIO_HAS_IOCP)
160
161 BOOST_ASIO_DECL signed_size_type recvfrom(socket_type s, buf* bufs,
162     size_t count, int flags, socket_addr_type* addr,
163     std::size_t* addrlen, boost::system::error_code& ec);
164
165 BOOST_ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state,
166     buf* bufs, size_t count, int flags, socket_addr_type* addr,
167     std::size_t* addrlen, boost::system::error_code& ec);
168
169 #if defined(BOOST_ASIO_HAS_IOCP)
170
171 BOOST_ASIO_DECL void complete_iocp_recvfrom(
172     const weak_cancel_token_type& cancel_token,
173     boost::system::error_code& ec);
174
175 #else // defined(BOOST_ASIO_HAS_IOCP)
176
177 BOOST_ASIO_DECL bool non_blocking_recvfrom(socket_type s,
178     buf* bufs, size_t count, int flags,
179     socket_addr_type* addr, std::size_t* addrlen,
180     boost::system::error_code& ec, size_t& bytes_transferred);
181
182 #endif // defined(BOOST_ASIO_HAS_IOCP)
183
184 BOOST_ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs,
185     size_t count, int in_flags, int& out_flags,
186     boost::system::error_code& ec);
187
188 BOOST_ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state,
189     buf* bufs, size_t count, int in_flags, int& out_flags,
190     boost::system::error_code& ec);
191
192 #if defined(BOOST_ASIO_HAS_IOCP)
193
194 BOOST_ASIO_DECL void complete_iocp_recvmsg(
195     const weak_cancel_token_type& cancel_token,
196     boost::system::error_code& ec);
197
198 #else // defined(BOOST_ASIO_HAS_IOCP)
199
200 BOOST_ASIO_DECL bool non_blocking_recvmsg(socket_type s,
201     buf* bufs, size_t count, int in_flags, int& out_flags,
202     boost::system::error_code& ec, size_t& bytes_transferred);
203
204 #endif // defined(BOOST_ASIO_HAS_IOCP)
205
206 BOOST_ASIO_DECL signed_size_type send(socket_type s, const buf* bufs,
207     size_t count, int flags, boost::system::error_code& ec);
208
209 BOOST_ASIO_DECL size_t sync_send(socket_type s, state_type state,
210     const buf* bufs, size_t count, int flags,
211     bool all_empty, boost::system::error_code& ec);
212
213 #if defined(BOOST_ASIO_HAS_IOCP)
214
215 BOOST_ASIO_DECL void complete_iocp_send(
216     const weak_cancel_token_type& cancel_token,
217     boost::system::error_code& ec);
218
219 #else // defined(BOOST_ASIO_HAS_IOCP)
220
221 BOOST_ASIO_DECL bool non_blocking_send(socket_type s,
222     const buf* bufs, size_t count, int flags,
223     boost::system::error_code& ec, size_t& bytes_transferred);
224
225 #endif // defined(BOOST_ASIO_HAS_IOCP)
226
227 BOOST_ASIO_DECL signed_size_type sendto(socket_type s, const buf* bufs,
228     size_t count, int flags, const socket_addr_type* addr,
229     std::size_t addrlen, boost::system::error_code& ec);
230
231 BOOST_ASIO_DECL size_t sync_sendto(socket_type s, state_type state,
232     const buf* bufs, size_t count, int flags, const socket_addr_type* addr,
233     std::size_t addrlen, boost::system::error_code& ec);
234
235 #if !defined(BOOST_ASIO_HAS_IOCP)
236
237 BOOST_ASIO_DECL bool non_blocking_sendto(socket_type s,
238     const buf* bufs, size_t count, int flags,
239     const socket_addr_type* addr, std::size_t addrlen,
240     boost::system::error_code& ec, size_t& bytes_transferred);
241
242 #endif // !defined(BOOST_ASIO_HAS_IOCP)
243
244 BOOST_ASIO_DECL socket_type socket(int af, int type, int protocol,
245     boost::system::error_code& ec);
246
247 BOOST_ASIO_DECL int setsockopt(socket_type s, state_type& state,
248     int level, int optname, const void* optval,
249     std::size_t optlen, boost::system::error_code& ec);
250
251 BOOST_ASIO_DECL int getsockopt(socket_type s, state_type state,
252     int level, int optname, void* optval,
253     size_t* optlen, boost::system::error_code& ec);
254
255 BOOST_ASIO_DECL int getpeername(socket_type s, socket_addr_type* addr,
256     std::size_t* addrlen, bool cached, boost::system::error_code& ec);
257
258 BOOST_ASIO_DECL int getsockname(socket_type s, socket_addr_type* addr,
259     std::size_t* addrlen, boost::system::error_code& ec);
260
261 BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state,
262     int cmd, ioctl_arg_type* arg, boost::system::error_code& ec);
263
264 BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds,
265     fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec);
266
267 BOOST_ASIO_DECL int poll_read(socket_type s,
268     state_type state, boost::system::error_code& ec);
269
270 BOOST_ASIO_DECL int poll_write(socket_type s,
271     state_type state, boost::system::error_code& ec);
272
273 BOOST_ASIO_DECL int poll_connect(socket_type s, boost::system::error_code& ec);
274
275 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
276
277 BOOST_ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest,
278     size_t length, unsigned long scope_id, boost::system::error_code& ec);
279
280 BOOST_ASIO_DECL int inet_pton(int af, const char* src, void* dest,
281     unsigned long* scope_id, boost::system::error_code& ec);
282
283 BOOST_ASIO_DECL int gethostname(char* name,
284     int namelen, boost::system::error_code& ec);
285
286 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
287
288 BOOST_ASIO_DECL boost::system::error_code getaddrinfo(const char* host,
289     const char* service, const addrinfo_type& hints,
290     addrinfo_type** result, boost::system::error_code& ec);
291
292 BOOST_ASIO_DECL boost::system::error_code background_getaddrinfo(
293     const weak_cancel_token_type& cancel_token, const char* host,
294     const char* service, const addrinfo_type& hints,
295     addrinfo_type** result, boost::system::error_code& ec);
296
297 BOOST_ASIO_DECL void freeaddrinfo(addrinfo_type* ai);
298
299 BOOST_ASIO_DECL boost::system::error_code getnameinfo(
300     const socket_addr_type* addr, std::size_t addrlen,
301     char* host, std::size_t hostlen, char* serv,
302     std::size_t servlen, int flags, boost::system::error_code& ec);
303
304 BOOST_ASIO_DECL boost::system::error_code sync_getnameinfo(
305     const socket_addr_type* addr, std::size_t addrlen,
306     char* host, std::size_t hostlen, char* serv,
307     std::size_t servlen, int sock_type, boost::system::error_code& ec);
308
309 BOOST_ASIO_DECL boost::system::error_code background_getnameinfo(
310     const weak_cancel_token_type& cancel_token,
311     const socket_addr_type* addr, std::size_t addrlen,
312     char* host, std::size_t hostlen, char* serv,
313     std::size_t servlen, int sock_type, boost::system::error_code& ec);
314
315 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
316
317 BOOST_ASIO_DECL u_long_type network_to_host_long(u_long_type value);
318
319 BOOST_ASIO_DECL u_long_type host_to_network_long(u_long_type value);
320
321 BOOST_ASIO_DECL u_short_type network_to_host_short(u_short_type value);
322
323 BOOST_ASIO_DECL u_short_type host_to_network_short(u_short_type value);
324
325 } // namespace socket_ops
326 } // namespace detail
327 } // namespace asio
328 } // namespace boost
329
330 #include <boost/asio/detail/pop_options.hpp>
331
332 #if defined(BOOST_ASIO_HEADER_ONLY)
333 # include <boost/asio/detail/impl/socket_ops.ipp>
334 #endif // defined(BOOST_ASIO_HEADER_ONLY)
335
336 #endif // BOOST_ASIO_DETAIL_SOCKET_OPS_HPP