Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:44

0001 //
0002 // detail/socket_ops.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_SOCKET_OPS_HPP
0012 #define BOOST_ASIO_DETAIL_SOCKET_OPS_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <boost/system/error_code.hpp>
0021 #include <boost/asio/detail/memory.hpp>
0022 #include <boost/asio/detail/socket_types.hpp>
0023 
0024 #include <boost/asio/detail/push_options.hpp>
0025 
0026 namespace boost {
0027 namespace asio {
0028 namespace detail {
0029 namespace socket_ops {
0030 
0031 // Socket state bits.
0032 enum
0033 {
0034   // The user wants a non-blocking socket.
0035   user_set_non_blocking = 1,
0036 
0037   // The socket has been set non-blocking.
0038   internal_non_blocking = 2,
0039 
0040   // Helper "state" used to determine whether the socket is non-blocking.
0041   non_blocking = user_set_non_blocking | internal_non_blocking,
0042 
0043   // User wants connection_aborted errors, which are disabled by default.
0044   enable_connection_aborted = 4,
0045 
0046   // The user set the linger option. Needs to be checked when closing.
0047   user_set_linger = 8,
0048 
0049   // The socket is stream-oriented.
0050   stream_oriented = 16,
0051 
0052   // The socket is datagram-oriented.
0053   datagram_oriented = 32,
0054 
0055   // The socket may have been dup()-ed.
0056   possible_dup = 64
0057 };
0058 
0059 typedef unsigned char state_type;
0060 
0061 struct noop_deleter { void operator()(void*) {} };
0062 typedef shared_ptr<void> shared_cancel_token_type;
0063 typedef weak_ptr<void> weak_cancel_token_type;
0064 
0065 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0066 
0067 BOOST_ASIO_DECL socket_type accept(socket_type s, void* addr,
0068     std::size_t* addrlen, boost::system::error_code& ec);
0069 
0070 BOOST_ASIO_DECL socket_type sync_accept(socket_type s, state_type state,
0071     void* addr, std::size_t* addrlen, boost::system::error_code& ec);
0072 
0073 #if defined(BOOST_ASIO_HAS_IOCP)
0074 
0075 BOOST_ASIO_DECL void complete_iocp_accept(socket_type s, void* output_buffer,
0076     DWORD address_length, void* addr, std::size_t* addrlen,
0077     socket_type new_socket, boost::system::error_code& ec);
0078 
0079 #else // defined(BOOST_ASIO_HAS_IOCP)
0080 
0081 BOOST_ASIO_DECL bool non_blocking_accept(socket_type s,
0082     state_type state, void* addr, std::size_t* addrlen,
0083     boost::system::error_code& ec, socket_type& new_socket);
0084 
0085 #endif // defined(BOOST_ASIO_HAS_IOCP)
0086 
0087 BOOST_ASIO_DECL int bind(socket_type s, const void* addr,
0088     std::size_t addrlen, boost::system::error_code& ec);
0089 
0090 BOOST_ASIO_DECL int close(socket_type s, state_type& state,
0091     bool destruction, boost::system::error_code& ec);
0092 
0093 BOOST_ASIO_DECL bool set_user_non_blocking(socket_type s,
0094     state_type& state, bool value, boost::system::error_code& ec);
0095 
0096 BOOST_ASIO_DECL bool set_internal_non_blocking(socket_type s,
0097     state_type& state, bool value, boost::system::error_code& ec);
0098 
0099 BOOST_ASIO_DECL int shutdown(socket_type s,
0100     int what, boost::system::error_code& ec);
0101 
0102 BOOST_ASIO_DECL int connect(socket_type s, const void* addr,
0103     std::size_t addrlen, boost::system::error_code& ec);
0104 
0105 BOOST_ASIO_DECL void sync_connect(socket_type s, const void* addr,
0106     std::size_t addrlen, boost::system::error_code& ec);
0107 
0108 #if defined(BOOST_ASIO_HAS_IOCP)
0109 
0110 BOOST_ASIO_DECL void complete_iocp_connect(socket_type s,
0111     boost::system::error_code& ec);
0112 
0113 #endif // defined(BOOST_ASIO_HAS_IOCP)
0114 
0115 BOOST_ASIO_DECL bool non_blocking_connect(socket_type s,
0116     boost::system::error_code& ec);
0117 
0118 BOOST_ASIO_DECL int socketpair(int af, int type, int protocol,
0119     socket_type sv[2], boost::system::error_code& ec);
0120 
0121 BOOST_ASIO_DECL bool sockatmark(socket_type s, boost::system::error_code& ec);
0122 
0123 BOOST_ASIO_DECL size_t available(socket_type s, boost::system::error_code& ec);
0124 
0125 BOOST_ASIO_DECL int listen(socket_type s,
0126     int backlog, boost::system::error_code& ec);
0127 
0128 #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
0129 typedef WSABUF buf;
0130 #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
0131 typedef iovec buf;
0132 #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
0133 
0134 BOOST_ASIO_DECL void init_buf(buf& b, void* data, size_t size);
0135 
0136 BOOST_ASIO_DECL void init_buf(buf& b, const void* data, size_t size);
0137 
0138 BOOST_ASIO_DECL signed_size_type recv(socket_type s, buf* bufs,
0139     size_t count, int flags, boost::system::error_code& ec);
0140 
0141 BOOST_ASIO_DECL signed_size_type recv1(socket_type s,
0142     void* data, size_t size, int flags, boost::system::error_code& ec);
0143 
0144 BOOST_ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs,
0145     size_t count, int flags, bool all_empty, boost::system::error_code& ec);
0146 
0147 BOOST_ASIO_DECL size_t sync_recv1(socket_type s, state_type state,
0148     void* data, size_t size, int flags, boost::system::error_code& ec);
0149 
0150 #if defined(BOOST_ASIO_HAS_IOCP)
0151 
0152 BOOST_ASIO_DECL void complete_iocp_recv(state_type state,
0153     const weak_cancel_token_type& cancel_token, bool all_empty,
0154     boost::system::error_code& ec, size_t bytes_transferred);
0155 
0156 #else // defined(BOOST_ASIO_HAS_IOCP)
0157 
0158 BOOST_ASIO_DECL bool non_blocking_recv(socket_type s,
0159     buf* bufs, size_t count, int flags, bool is_stream,
0160     boost::system::error_code& ec, size_t& bytes_transferred);
0161 
0162 BOOST_ASIO_DECL bool non_blocking_recv1(socket_type s,
0163     void* data, size_t size, int flags, bool is_stream,
0164     boost::system::error_code& ec, size_t& bytes_transferred);
0165 
0166 #endif // defined(BOOST_ASIO_HAS_IOCP)
0167 
0168 BOOST_ASIO_DECL signed_size_type recvfrom(socket_type s,
0169     buf* bufs, size_t count, int flags, void* addr,
0170     std::size_t* addrlen, boost::system::error_code& ec);
0171 
0172 BOOST_ASIO_DECL signed_size_type recvfrom1(socket_type s,
0173     void* data, size_t size, int flags, void* addr,
0174     std::size_t* addrlen, boost::system::error_code& ec);
0175 
0176 BOOST_ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state,
0177     buf* bufs, size_t count, int flags, void* addr,
0178     std::size_t* addrlen, boost::system::error_code& ec);
0179 
0180 BOOST_ASIO_DECL size_t sync_recvfrom1(socket_type s, state_type state,
0181     void* data, size_t size, int flags, void* addr,
0182     std::size_t* addrlen, boost::system::error_code& ec);
0183 
0184 #if defined(BOOST_ASIO_HAS_IOCP)
0185 
0186 BOOST_ASIO_DECL void complete_iocp_recvfrom(
0187     const weak_cancel_token_type& cancel_token,
0188     boost::system::error_code& ec);
0189 
0190 #else // defined(BOOST_ASIO_HAS_IOCP)
0191 
0192 BOOST_ASIO_DECL bool non_blocking_recvfrom(socket_type s, buf* bufs,
0193     size_t count, int flags, void* addr, std::size_t* addrlen,
0194     boost::system::error_code& ec, size_t& bytes_transferred);
0195 
0196 BOOST_ASIO_DECL bool non_blocking_recvfrom1(socket_type s, void* data,
0197     size_t size, int flags, void* addr, std::size_t* addrlen,
0198     boost::system::error_code& ec, size_t& bytes_transferred);
0199 
0200 #endif // defined(BOOST_ASIO_HAS_IOCP)
0201 
0202 BOOST_ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs,
0203     size_t count, int in_flags, int& out_flags,
0204     boost::system::error_code& ec);
0205 
0206 BOOST_ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state,
0207     buf* bufs, size_t count, int in_flags, int& out_flags,
0208     boost::system::error_code& ec);
0209 
0210 #if defined(BOOST_ASIO_HAS_IOCP)
0211 
0212 BOOST_ASIO_DECL void complete_iocp_recvmsg(
0213     const weak_cancel_token_type& cancel_token,
0214     boost::system::error_code& ec);
0215 
0216 #else // defined(BOOST_ASIO_HAS_IOCP)
0217 
0218 BOOST_ASIO_DECL bool non_blocking_recvmsg(socket_type s,
0219     buf* bufs, size_t count, int in_flags, int& out_flags,
0220     boost::system::error_code& ec, size_t& bytes_transferred);
0221 
0222 #endif // defined(BOOST_ASIO_HAS_IOCP)
0223 
0224 BOOST_ASIO_DECL signed_size_type send(socket_type s, const buf* bufs,
0225     size_t count, int flags, boost::system::error_code& ec);
0226 
0227 BOOST_ASIO_DECL signed_size_type send1(socket_type s,
0228     const void* data, size_t size, int flags, boost::system::error_code& ec);
0229 
0230 BOOST_ASIO_DECL size_t sync_send(socket_type s, state_type state,
0231     const buf* bufs, size_t count, int flags,
0232     bool all_empty, boost::system::error_code& ec);
0233 
0234 BOOST_ASIO_DECL size_t sync_send1(socket_type s, state_type state,
0235     const void* data, size_t size, int flags, boost::system::error_code& ec);
0236 
0237 #if defined(BOOST_ASIO_HAS_IOCP)
0238 
0239 BOOST_ASIO_DECL void complete_iocp_send(
0240     const weak_cancel_token_type& cancel_token,
0241     boost::system::error_code& ec);
0242 
0243 #else // defined(BOOST_ASIO_HAS_IOCP)
0244 
0245 BOOST_ASIO_DECL bool non_blocking_send(socket_type s,
0246     const buf* bufs, size_t count, int flags,
0247     boost::system::error_code& ec, size_t& bytes_transferred);
0248 
0249 BOOST_ASIO_DECL bool non_blocking_send1(socket_type s,
0250     const void* data, size_t size, int flags,
0251     boost::system::error_code& ec, size_t& bytes_transferred);
0252 
0253 #endif // defined(BOOST_ASIO_HAS_IOCP)
0254 
0255 BOOST_ASIO_DECL signed_size_type sendto(socket_type s,
0256     const buf* bufs, size_t count, int flags, const void* addr,
0257     std::size_t addrlen, boost::system::error_code& ec);
0258 
0259 BOOST_ASIO_DECL signed_size_type sendto1(socket_type s,
0260     const void* data, size_t size, int flags, const void* addr,
0261     std::size_t addrlen, boost::system::error_code& ec);
0262 
0263 BOOST_ASIO_DECL size_t sync_sendto(socket_type s, state_type state,
0264     const buf* bufs, size_t count, int flags, const void* addr,
0265     std::size_t addrlen, boost::system::error_code& ec);
0266 
0267 BOOST_ASIO_DECL size_t sync_sendto1(socket_type s, state_type state,
0268     const void* data, size_t size, int flags, const void* addr,
0269     std::size_t addrlen, boost::system::error_code& ec);
0270 
0271 #if !defined(BOOST_ASIO_HAS_IOCP)
0272 
0273 BOOST_ASIO_DECL bool non_blocking_sendto(socket_type s, const buf* bufs,
0274     size_t count, int flags, const void* addr, std::size_t addrlen,
0275     boost::system::error_code& ec, size_t& bytes_transferred);
0276 
0277 BOOST_ASIO_DECL bool non_blocking_sendto1(socket_type s, const void* data,
0278     size_t size, int flags, const void* addr, std::size_t addrlen,
0279     boost::system::error_code& ec, size_t& bytes_transferred);
0280 
0281 #endif // !defined(BOOST_ASIO_HAS_IOCP)
0282 
0283 BOOST_ASIO_DECL socket_type socket(int af, int type, int protocol,
0284     boost::system::error_code& ec);
0285 
0286 BOOST_ASIO_DECL int setsockopt(socket_type s, state_type& state,
0287     int level, int optname, const void* optval,
0288     std::size_t optlen, boost::system::error_code& ec);
0289 
0290 BOOST_ASIO_DECL int getsockopt(socket_type s, state_type state,
0291     int level, int optname, void* optval,
0292     size_t* optlen, boost::system::error_code& ec);
0293 
0294 BOOST_ASIO_DECL int getpeername(socket_type s, void* addr,
0295     std::size_t* addrlen, bool cached, boost::system::error_code& ec);
0296 
0297 BOOST_ASIO_DECL int getsockname(socket_type s, void* addr,
0298     std::size_t* addrlen, boost::system::error_code& ec);
0299 
0300 BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state,
0301     int cmd, ioctl_arg_type* arg, boost::system::error_code& ec);
0302 
0303 BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds,
0304     fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec);
0305 
0306 BOOST_ASIO_DECL int poll_read(socket_type s,
0307     state_type state, int msec, boost::system::error_code& ec);
0308 
0309 BOOST_ASIO_DECL int poll_write(socket_type s,
0310     state_type state, int msec, boost::system::error_code& ec);
0311 
0312 BOOST_ASIO_DECL int poll_error(socket_type s,
0313     state_type state, int msec, boost::system::error_code& ec);
0314 
0315 BOOST_ASIO_DECL int poll_connect(socket_type s,
0316     int msec, boost::system::error_code& ec);
0317 
0318 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0319 
0320 BOOST_ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest,
0321     size_t length, unsigned long scope_id, boost::system::error_code& ec);
0322 
0323 BOOST_ASIO_DECL int inet_pton(int af, const char* src, void* dest,
0324     unsigned long* scope_id, boost::system::error_code& ec);
0325 
0326 BOOST_ASIO_DECL int gethostname(char* name,
0327     int namelen, boost::system::error_code& ec);
0328 
0329 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0330 
0331 BOOST_ASIO_DECL boost::system::error_code getaddrinfo(const char* host,
0332     const char* service, const addrinfo_type& hints,
0333     addrinfo_type** result, boost::system::error_code& ec);
0334 
0335 BOOST_ASIO_DECL boost::system::error_code background_getaddrinfo(
0336     const weak_cancel_token_type& cancel_token, const char* host,
0337     const char* service, const addrinfo_type& hints,
0338     addrinfo_type** result, boost::system::error_code& ec);
0339 
0340 BOOST_ASIO_DECL void freeaddrinfo(addrinfo_type* ai);
0341 
0342 BOOST_ASIO_DECL boost::system::error_code getnameinfo(const void* addr,
0343     std::size_t addrlen, char* host, std::size_t hostlen, char* serv,
0344     std::size_t servlen, int flags, boost::system::error_code& ec);
0345 
0346 BOOST_ASIO_DECL boost::system::error_code sync_getnameinfo(const void* addr,
0347     std::size_t addrlen, char* host, std::size_t hostlen, char* serv,
0348     std::size_t servlen, int sock_type, boost::system::error_code& ec);
0349 
0350 BOOST_ASIO_DECL boost::system::error_code background_getnameinfo(
0351     const weak_cancel_token_type& cancel_token,
0352     const void* addr, std::size_t addrlen,
0353     char* host, std::size_t hostlen, char* serv,
0354     std::size_t servlen, int sock_type, boost::system::error_code& ec);
0355 
0356 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0357 
0358 BOOST_ASIO_DECL u_long_type network_to_host_long(u_long_type value);
0359 
0360 BOOST_ASIO_DECL u_long_type host_to_network_long(u_long_type value);
0361 
0362 BOOST_ASIO_DECL u_short_type network_to_host_short(u_short_type value);
0363 
0364 BOOST_ASIO_DECL u_short_type host_to_network_short(u_short_type value);
0365 
0366 } // namespace socket_ops
0367 } // namespace detail
0368 } // namespace asio
0369 } // namespace boost
0370 
0371 #include <boost/asio/detail/pop_options.hpp>
0372 
0373 #if defined(BOOST_ASIO_HEADER_ONLY)
0374 # include <boost/asio/detail/impl/socket_ops.ipp>
0375 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0376 
0377 #endif // BOOST_ASIO_DETAIL_SOCKET_OPS_HPP