Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
10KB

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