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.

socket_ops.hpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. //
  2. // detail/socket_ops.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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, int msec, asio::error_code& ec);
  184. ASIO_DECL int poll_write(socket_type s,
  185. state_type state, int msec, asio::error_code& ec);
  186. ASIO_DECL int poll_error(socket_type s,
  187. state_type state, int msec, asio::error_code& ec);
  188. ASIO_DECL int poll_connect(socket_type s,
  189. int msec, asio::error_code& ec);
  190. #endif // !defined(ASIO_WINDOWS_RUNTIME)
  191. ASIO_DECL const char* inet_ntop(int af, const void* src, char* dest,
  192. size_t length, unsigned long scope_id, asio::error_code& ec);
  193. ASIO_DECL int inet_pton(int af, const char* src, void* dest,
  194. unsigned long* scope_id, asio::error_code& ec);
  195. ASIO_DECL int gethostname(char* name,
  196. int namelen, asio::error_code& ec);
  197. #if !defined(ASIO_WINDOWS_RUNTIME)
  198. ASIO_DECL asio::error_code getaddrinfo(const char* host,
  199. const char* service, const addrinfo_type& hints,
  200. addrinfo_type** result, asio::error_code& ec);
  201. ASIO_DECL asio::error_code background_getaddrinfo(
  202. const weak_cancel_token_type& cancel_token, const char* host,
  203. const char* service, const addrinfo_type& hints,
  204. addrinfo_type** result, asio::error_code& ec);
  205. ASIO_DECL void freeaddrinfo(addrinfo_type* ai);
  206. ASIO_DECL asio::error_code getnameinfo(
  207. const socket_addr_type* addr, std::size_t addrlen,
  208. char* host, std::size_t hostlen, char* serv,
  209. std::size_t servlen, int flags, asio::error_code& ec);
  210. ASIO_DECL asio::error_code sync_getnameinfo(
  211. const socket_addr_type* addr, std::size_t addrlen,
  212. char* host, std::size_t hostlen, char* serv,
  213. std::size_t servlen, int sock_type, asio::error_code& ec);
  214. ASIO_DECL asio::error_code background_getnameinfo(
  215. const weak_cancel_token_type& cancel_token,
  216. const socket_addr_type* addr, std::size_t addrlen,
  217. char* host, std::size_t hostlen, char* serv,
  218. std::size_t servlen, int sock_type, asio::error_code& ec);
  219. #endif // !defined(ASIO_WINDOWS_RUNTIME)
  220. ASIO_DECL u_long_type network_to_host_long(u_long_type value);
  221. ASIO_DECL u_long_type host_to_network_long(u_long_type value);
  222. ASIO_DECL u_short_type network_to_host_short(u_short_type value);
  223. ASIO_DECL u_short_type host_to_network_short(u_short_type value);
  224. } // namespace socket_ops
  225. } // namespace detail
  226. } // namespace asio
  227. #include "asio/detail/pop_options.hpp"
  228. #if defined(ASIO_HEADER_ONLY)
  229. # include "asio/detail/impl/socket_ops.ipp"
  230. #endif // defined(ASIO_HEADER_ONLY)
  231. #endif // ASIO_DETAIL_SOCKET_OPS_HPP