• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // detail/socket_ops.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_DETAIL_SOCKET_OPS_HPP
12 #define ASIO_DETAIL_SOCKET_OPS_HPP
13 
14 
15 #include "asio/detail/config.hpp"
16 
17 #include "asio/error_code.hpp"
18 #include "asio/detail/shared_ptr.hpp"
19 #include "asio/detail/socket_types.hpp"
20 #include "asio/detail/weak_ptr.hpp"
21 
22 #include "asio/detail/push_options.hpp"
23 
24 namespace asio {
25 namespace detail {
26 namespace socket_ops {
27 
28 // Socket state bits.
29 enum
30 {
31   // The user wants a non-blocking socket.
32   user_set_non_blocking = 1,
33 
34   // The socket has been set non-blocking.
35   internal_non_blocking = 2,
36 
37   // Helper "state" used to determine whether the socket is non-blocking.
38   non_blocking = user_set_non_blocking | internal_non_blocking,
39 
40   // User wants connection_aborted errors, which are disabled by default.
41   enable_connection_aborted = 4,
42 
43   // The user set the linger option. Needs to be checked when closing.
44   user_set_linger = 8,
45 
46   // The socket is stream-oriented.
47   stream_oriented = 16,
48 
49   // The socket is datagram-oriented.
50   datagram_oriented = 32,
51 
52   // The socket may have been dup()-ed.
53   possible_dup = 64
54 };
55 
56 typedef unsigned char state_type;
57 
operator ()asio::detail::socket_ops::noop_deleter58 struct noop_deleter { void operator()(void*) {} };
59 typedef shared_ptr<void> shared_cancel_token_type;
60 typedef weak_ptr<void> weak_cancel_token_type;
61 
62 
63 ASIO_DECL socket_type accept(socket_type s, socket_addr_type* addr,
64     std::size_t* addrlen, asio::error_code& ec);
65 
66 ASIO_DECL socket_type sync_accept(socket_type s,
67     state_type state, socket_addr_type* addr,
68     std::size_t* addrlen, asio::error_code& ec);
69 
70 
71 ASIO_DECL bool non_blocking_accept(socket_type s,
72     state_type state, socket_addr_type* addr, std::size_t* addrlen,
73     asio::error_code& ec, socket_type& new_socket);
74 
75 
76 ASIO_DECL int bind(socket_type s, const socket_addr_type* addr,
77     std::size_t addrlen, asio::error_code& ec);
78 
79 ASIO_DECL int close(socket_type s, state_type& state,
80     bool destruction, asio::error_code& ec);
81 
82 ASIO_DECL bool set_user_non_blocking(socket_type s,
83     state_type& state, bool value, asio::error_code& ec);
84 
85 ASIO_DECL bool set_internal_non_blocking(socket_type s,
86     state_type& state, bool value, asio::error_code& ec);
87 
88 ASIO_DECL int shutdown(socket_type s,
89     int what, asio::error_code& ec);
90 
91 ASIO_DECL int connect(socket_type s, const socket_addr_type* addr,
92     std::size_t addrlen, asio::error_code& ec);
93 
94 ASIO_DECL void sync_connect(socket_type s, const socket_addr_type* addr,
95     std::size_t addrlen, asio::error_code& ec);
96 
97 
98 ASIO_DECL bool non_blocking_connect(socket_type s,
99     asio::error_code& ec);
100 
101 ASIO_DECL int socketpair(int af, int type, int protocol,
102     socket_type sv[2], asio::error_code& ec);
103 
104 ASIO_DECL bool sockatmark(socket_type s, asio::error_code& ec);
105 
106 ASIO_DECL size_t available(socket_type s, asio::error_code& ec);
107 
108 ASIO_DECL int listen(socket_type s,
109     int backlog, asio::error_code& ec);
110 
111 typedef iovec buf;
112 
113 ASIO_DECL void init_buf(buf& b, void* data, size_t size);
114 
115 ASIO_DECL void init_buf(buf& b, const void* data, size_t size);
116 
117 ASIO_DECL signed_size_type recv(socket_type s, buf* bufs,
118     size_t count, int flags, asio::error_code& ec);
119 
120 ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs,
121     size_t count, int flags, bool all_empty, asio::error_code& ec);
122 
123 
124 ASIO_DECL bool non_blocking_recv(socket_type s,
125     buf* bufs, size_t count, int flags, bool is_stream,
126     asio::error_code& ec, size_t& bytes_transferred);
127 
128 
129 ASIO_DECL signed_size_type recvfrom(socket_type s, buf* bufs,
130     size_t count, int flags, socket_addr_type* addr,
131     std::size_t* addrlen, asio::error_code& ec);
132 
133 ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state,
134     buf* bufs, size_t count, int flags, socket_addr_type* addr,
135     std::size_t* addrlen, asio::error_code& ec);
136 
137 
138 ASIO_DECL bool non_blocking_recvfrom(socket_type s,
139     buf* bufs, size_t count, int flags,
140     socket_addr_type* addr, std::size_t* addrlen,
141     asio::error_code& ec, size_t& bytes_transferred);
142 
143 
144 ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs,
145     size_t count, int in_flags, int& out_flags,
146     asio::error_code& ec);
147 
148 ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state,
149     buf* bufs, size_t count, int in_flags, int& out_flags,
150     asio::error_code& ec);
151 
152 
153 ASIO_DECL bool non_blocking_recvmsg(socket_type s,
154     buf* bufs, size_t count, int in_flags, int& out_flags,
155     asio::error_code& ec, size_t& bytes_transferred);
156 
157 
158 ASIO_DECL signed_size_type send(socket_type s, const buf* bufs,
159     size_t count, int flags, asio::error_code& ec);
160 
161 ASIO_DECL size_t sync_send(socket_type s, state_type state,
162     const buf* bufs, size_t count, int flags,
163     bool all_empty, asio::error_code& ec);
164 
165 
166 ASIO_DECL bool non_blocking_send(socket_type s,
167     const buf* bufs, size_t count, int flags,
168     asio::error_code& ec, size_t& bytes_transferred);
169 
170 
171 ASIO_DECL signed_size_type sendto(socket_type s, const buf* bufs,
172     size_t count, int flags, const socket_addr_type* addr,
173     std::size_t addrlen, asio::error_code& ec);
174 
175 ASIO_DECL size_t sync_sendto(socket_type s, state_type state,
176     const buf* bufs, size_t count, int flags, const socket_addr_type* addr,
177     std::size_t addrlen, asio::error_code& ec);
178 
179 
180 ASIO_DECL bool non_blocking_sendto(socket_type s,
181     const buf* bufs, size_t count, int flags,
182     const socket_addr_type* addr, std::size_t addrlen,
183     asio::error_code& ec, size_t& bytes_transferred);
184 
185 
186 ASIO_DECL socket_type socket(int af, int type, int protocol,
187     asio::error_code& ec);
188 
189 ASIO_DECL int setsockopt(socket_type s, state_type& state,
190     int level, int optname, const void* optval,
191     std::size_t optlen, asio::error_code& ec);
192 
193 ASIO_DECL int getsockopt(socket_type s, state_type state,
194     int level, int optname, void* optval,
195     size_t* optlen, asio::error_code& ec);
196 
197 ASIO_DECL int getpeername(socket_type s, socket_addr_type* addr,
198     std::size_t* addrlen, bool cached, asio::error_code& ec);
199 
200 ASIO_DECL int getsockname(socket_type s, socket_addr_type* addr,
201     std::size_t* addrlen, asio::error_code& ec);
202 
203 ASIO_DECL int ioctl(socket_type s, state_type& state,
204     int cmd, ioctl_arg_type* arg, asio::error_code& ec);
205 
206 ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds,
207     fd_set* exceptfds, timeval* timeout, asio::error_code& ec);
208 
209 ASIO_DECL int poll_read(socket_type s,
210     state_type state, asio::error_code& ec);
211 
212 ASIO_DECL int poll_write(socket_type s,
213     state_type state, asio::error_code& ec);
214 
215 ASIO_DECL int poll_connect(socket_type s, asio::error_code& ec);
216 
217 
218 ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest,
219     size_t length, unsigned long scope_id, asio::error_code& ec);
220 
221 ASIO_DECL int inet_pton(int af, const char* src, void* dest,
222     unsigned long* scope_id, asio::error_code& ec);
223 
224 ASIO_DECL int gethostname(char* name,
225     int namelen, asio::error_code& ec);
226 
227 
228 ASIO_DECL asio::error_code getaddrinfo(const char* host,
229     const char* service, const addrinfo_type& hints,
230     addrinfo_type** result, asio::error_code& ec);
231 
232 ASIO_DECL asio::error_code background_getaddrinfo(
233     const weak_cancel_token_type& cancel_token, const char* host,
234     const char* service, const addrinfo_type& hints,
235     addrinfo_type** result, asio::error_code& ec);
236 
237 ASIO_DECL void freeaddrinfo(addrinfo_type* ai);
238 
239 ASIO_DECL asio::error_code getnameinfo(
240     const socket_addr_type* addr, std::size_t addrlen,
241     char* host, std::size_t hostlen, char* serv,
242     std::size_t servlen, int flags, asio::error_code& ec);
243 
244 ASIO_DECL asio::error_code sync_getnameinfo(
245     const socket_addr_type* addr, std::size_t addrlen,
246     char* host, std::size_t hostlen, char* serv,
247     std::size_t servlen, int sock_type, asio::error_code& ec);
248 
249 ASIO_DECL asio::error_code background_getnameinfo(
250     const weak_cancel_token_type& cancel_token,
251     const socket_addr_type* addr, std::size_t addrlen,
252     char* host, std::size_t hostlen, char* serv,
253     std::size_t servlen, int sock_type, asio::error_code& ec);
254 
255 
256 ASIO_DECL u_long_type network_to_host_long(u_long_type value);
257 
258 ASIO_DECL u_long_type host_to_network_long(u_long_type value);
259 
260 ASIO_DECL u_short_type network_to_host_short(u_short_type value);
261 
262 ASIO_DECL u_short_type host_to_network_short(u_short_type value);
263 
264 } // namespace socket_ops
265 } // namespace detail
266 } // namespace asio
267 
268 #include "asio/detail/pop_options.hpp"
269 
270 # include "asio/detail/impl/socket_ops.ipp"
271 
272 #endif // ASIO_DETAIL_SOCKET_OPS_HPP
273