Chris@16: // Chris@16: // detail/socket_ops.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_SOCKET_OPS_HPP Chris@16: #define BOOST_ASIO_DETAIL_SOCKET_OPS_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: namespace socket_ops { Chris@16: Chris@16: // Socket state bits. Chris@16: enum Chris@16: { Chris@16: // The user wants a non-blocking socket. Chris@16: user_set_non_blocking = 1, Chris@16: Chris@16: // The socket has been set non-blocking. Chris@16: internal_non_blocking = 2, Chris@16: Chris@16: // Helper "state" used to determine whether the socket is non-blocking. Chris@16: non_blocking = user_set_non_blocking | internal_non_blocking, Chris@16: Chris@16: // User wants connection_aborted errors, which are disabled by default. Chris@16: enable_connection_aborted = 4, Chris@16: Chris@16: // The user set the linger option. Needs to be checked when closing. Chris@16: user_set_linger = 8, Chris@16: Chris@16: // The socket is stream-oriented. Chris@16: stream_oriented = 16, Chris@16: Chris@16: // The socket is datagram-oriented. Chris@16: datagram_oriented = 32, Chris@16: Chris@16: // The socket may have been dup()-ed. Chris@16: possible_dup = 64 Chris@16: }; Chris@16: Chris@16: typedef unsigned char state_type; Chris@16: Chris@16: struct noop_deleter { void operator()(void*) {} }; Chris@16: typedef shared_ptr shared_cancel_token_type; Chris@16: typedef weak_ptr weak_cancel_token_type; Chris@16: Chris@16: #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: BOOST_ASIO_DECL socket_type accept(socket_type s, socket_addr_type* addr, Chris@16: std::size_t* addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL socket_type sync_accept(socket_type s, Chris@16: state_type state, socket_addr_type* addr, Chris@16: std::size_t* addrlen, boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL void complete_iocp_accept(socket_type s, Chris@16: void* output_buffer, DWORD address_length, Chris@16: socket_addr_type* addr, std::size_t* addrlen, Chris@16: socket_type new_socket, boost::system::error_code& ec); Chris@16: Chris@16: #else // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_accept(socket_type s, Chris@16: state_type state, socket_addr_type* addr, std::size_t* addrlen, Chris@16: boost::system::error_code& ec, socket_type& new_socket); Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL int bind(socket_type s, const socket_addr_type* addr, Chris@16: std::size_t addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int close(socket_type s, state_type& state, Chris@16: bool destruction, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL bool set_user_non_blocking(socket_type s, Chris@16: state_type& state, bool value, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL bool set_internal_non_blocking(socket_type s, Chris@16: state_type& state, bool value, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int shutdown(socket_type s, Chris@16: int what, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int connect(socket_type s, const socket_addr_type* addr, Chris@16: std::size_t addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL void sync_connect(socket_type s, const socket_addr_type* addr, Chris@16: std::size_t addrlen, boost::system::error_code& ec); Chris@16: Chris@101: #if defined(BOOST_ASIO_HAS_IOCP) Chris@101: Chris@101: BOOST_ASIO_DECL void complete_iocp_connect(socket_type s, Chris@101: boost::system::error_code& ec); Chris@101: Chris@101: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@101: Chris@16: BOOST_ASIO_DECL bool non_blocking_connect(socket_type s, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int socketpair(int af, int type, int protocol, Chris@16: socket_type sv[2], boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL bool sockatmark(socket_type s, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t available(socket_type s, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int listen(socket_type s, Chris@16: int backlog, boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) Chris@16: typedef WSABUF buf; Chris@16: #else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) Chris@16: typedef iovec buf; Chris@16: #endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) Chris@16: Chris@16: BOOST_ASIO_DECL void init_buf(buf& b, void* data, size_t size); Chris@16: Chris@16: BOOST_ASIO_DECL void init_buf(buf& b, const void* data, size_t size); Chris@16: Chris@16: BOOST_ASIO_DECL signed_size_type recv(socket_type s, buf* bufs, Chris@16: size_t count, int flags, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t sync_recv(socket_type s, state_type state, buf* bufs, Chris@16: size_t count, int flags, bool all_empty, boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL void complete_iocp_recv(state_type state, Chris@16: const weak_cancel_token_type& cancel_token, bool all_empty, Chris@16: boost::system::error_code& ec, size_t bytes_transferred); Chris@16: Chris@16: #else // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_recv(socket_type s, Chris@16: buf* bufs, size_t count, int flags, bool is_stream, Chris@16: boost::system::error_code& ec, size_t& bytes_transferred); Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL signed_size_type recvfrom(socket_type s, buf* bufs, Chris@16: size_t count, int flags, socket_addr_type* addr, Chris@16: std::size_t* addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t sync_recvfrom(socket_type s, state_type state, Chris@16: buf* bufs, size_t count, int flags, socket_addr_type* addr, Chris@16: std::size_t* addrlen, boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL void complete_iocp_recvfrom( Chris@16: const weak_cancel_token_type& cancel_token, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: #else // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_recvfrom(socket_type s, Chris@16: buf* bufs, size_t count, int flags, Chris@16: socket_addr_type* addr, std::size_t* addrlen, Chris@16: boost::system::error_code& ec, size_t& bytes_transferred); Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL signed_size_type recvmsg(socket_type s, buf* bufs, Chris@16: size_t count, int in_flags, int& out_flags, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t sync_recvmsg(socket_type s, state_type state, Chris@16: buf* bufs, size_t count, int in_flags, int& out_flags, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL void complete_iocp_recvmsg( Chris@16: const weak_cancel_token_type& cancel_token, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: #else // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_recvmsg(socket_type s, Chris@16: buf* bufs, size_t count, int in_flags, int& out_flags, Chris@16: boost::system::error_code& ec, size_t& bytes_transferred); Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL signed_size_type send(socket_type s, const buf* bufs, Chris@16: size_t count, int flags, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t sync_send(socket_type s, state_type state, Chris@16: const buf* bufs, size_t count, int flags, Chris@16: bool all_empty, boost::system::error_code& ec); Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL void complete_iocp_send( Chris@16: const weak_cancel_token_type& cancel_token, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: #else // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_send(socket_type s, Chris@16: const buf* bufs, size_t count, int flags, Chris@16: boost::system::error_code& ec, size_t& bytes_transferred); Chris@16: Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL signed_size_type sendto(socket_type s, const buf* bufs, Chris@16: size_t count, int flags, const socket_addr_type* addr, Chris@16: std::size_t addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL size_t sync_sendto(socket_type s, state_type state, Chris@16: const buf* bufs, size_t count, int flags, const socket_addr_type* addr, Chris@16: std::size_t addrlen, boost::system::error_code& ec); Chris@16: Chris@16: #if !defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL bool non_blocking_sendto(socket_type s, Chris@16: const buf* bufs, size_t count, int flags, Chris@16: const socket_addr_type* addr, std::size_t addrlen, Chris@16: boost::system::error_code& ec, size_t& bytes_transferred); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: BOOST_ASIO_DECL socket_type socket(int af, int type, int protocol, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int setsockopt(socket_type s, state_type& state, Chris@16: int level, int optname, const void* optval, Chris@16: std::size_t optlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int getsockopt(socket_type s, state_type state, Chris@16: int level, int optname, void* optval, Chris@16: size_t* optlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int getpeername(socket_type s, socket_addr_type* addr, Chris@16: std::size_t* addrlen, bool cached, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int getsockname(socket_type s, socket_addr_type* addr, Chris@16: std::size_t* addrlen, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state, Chris@16: int cmd, ioctl_arg_type* arg, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds, Chris@16: fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int poll_read(socket_type s, Chris@16: state_type state, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int poll_write(socket_type s, Chris@16: state_type state, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int poll_connect(socket_type s, boost::system::error_code& ec); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: BOOST_ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest, Chris@16: size_t length, unsigned long scope_id, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int inet_pton(int af, const char* src, void* dest, Chris@16: unsigned long* scope_id, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL int gethostname(char* name, Chris@16: int namelen, boost::system::error_code& ec); Chris@16: Chris@16: #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: BOOST_ASIO_DECL boost::system::error_code getaddrinfo(const char* host, Chris@16: const char* service, const addrinfo_type& hints, Chris@16: addrinfo_type** result, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL boost::system::error_code background_getaddrinfo( Chris@16: const weak_cancel_token_type& cancel_token, const char* host, Chris@16: const char* service, const addrinfo_type& hints, Chris@16: addrinfo_type** result, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL void freeaddrinfo(addrinfo_type* ai); Chris@16: Chris@16: BOOST_ASIO_DECL boost::system::error_code getnameinfo( Chris@16: const socket_addr_type* addr, std::size_t addrlen, Chris@16: char* host, std::size_t hostlen, char* serv, Chris@16: std::size_t servlen, int flags, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL boost::system::error_code sync_getnameinfo( Chris@16: const socket_addr_type* addr, std::size_t addrlen, Chris@16: char* host, std::size_t hostlen, char* serv, Chris@16: std::size_t servlen, int sock_type, boost::system::error_code& ec); Chris@16: Chris@16: BOOST_ASIO_DECL boost::system::error_code background_getnameinfo( Chris@16: const weak_cancel_token_type& cancel_token, Chris@16: const socket_addr_type* addr, std::size_t addrlen, Chris@16: char* host, std::size_t hostlen, char* serv, Chris@16: std::size_t servlen, int sock_type, boost::system::error_code& ec); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: BOOST_ASIO_DECL u_long_type network_to_host_long(u_long_type value); Chris@16: Chris@16: BOOST_ASIO_DECL u_long_type host_to_network_long(u_long_type value); Chris@16: Chris@16: BOOST_ASIO_DECL u_short_type network_to_host_short(u_short_type value); Chris@16: Chris@16: BOOST_ASIO_DECL u_short_type host_to_network_short(u_short_type value); Chris@16: Chris@16: } // namespace socket_ops Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_SOCKET_OPS_HPP