PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/boost_1_57_0/libs/asio/test/generic/stream_protocol.cpp

http://github.com/MisterTea/HyperNEAT
C++ | 241 lines | 165 code | 53 blank | 23 comment | 1 complexity | 2a4caf55a69421b9e813427e27e758bf MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0, GPL-3.0, GPL-2.0
  1. //
  2. // generic/stream_protocol.cpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2014 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. // Disable autolinking for unit tests.
  11. #if !defined(BOOST_ALL_NO_LIB)
  12. #define BOOST_ALL_NO_LIB 1
  13. #endif // !defined(BOOST_ALL_NO_LIB)
  14. // Test that header file is self-contained.
  15. #include <boost/asio/generic/stream_protocol.hpp>
  16. #include <cstring>
  17. #include <boost/asio/io_service.hpp>
  18. #include <boost/asio/ip/tcp.hpp>
  19. #include "../unit_test.hpp"
  20. #if defined(__cplusplus_cli) || defined(__cplusplus_winrt)
  21. # define generic cpp_generic
  22. #endif
  23. //------------------------------------------------------------------------------
  24. // generic_stream_protocol_socket_compile test
  25. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. // The following test checks that all public member functions on the class
  27. // generic::stream_protocol::socket compile and link correctly. Runtime
  28. // failures are ignored.
  29. namespace generic_stream_protocol_socket_compile {
  30. void connect_handler(const boost::system::error_code&)
  31. {
  32. }
  33. void send_handler(const boost::system::error_code&, std::size_t)
  34. {
  35. }
  36. void receive_handler(const boost::system::error_code&, std::size_t)
  37. {
  38. }
  39. void write_some_handler(const boost::system::error_code&, std::size_t)
  40. {
  41. }
  42. void read_some_handler(const boost::system::error_code&, std::size_t)
  43. {
  44. }
  45. void test()
  46. {
  47. using namespace boost::asio;
  48. namespace generic = boost::asio::generic;
  49. typedef generic::stream_protocol sp;
  50. const int af_inet = BOOST_ASIO_OS_DEF(AF_INET);
  51. const int ipproto_tcp = BOOST_ASIO_OS_DEF(IPPROTO_TCP);
  52. const int sock_stream = BOOST_ASIO_OS_DEF(SOCK_STREAM);
  53. try
  54. {
  55. io_service ios;
  56. char mutable_char_buffer[128] = "";
  57. const char const_char_buffer[128] = "";
  58. socket_base::message_flags in_flags = 0;
  59. socket_base::keep_alive socket_option;
  60. socket_base::bytes_readable io_control_command;
  61. boost::system::error_code ec;
  62. // basic_stream_socket constructors.
  63. sp::socket socket1(ios);
  64. sp::socket socket2(ios, sp(af_inet, ipproto_tcp));
  65. sp::socket socket3(ios, sp::endpoint());
  66. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  67. Windows::Networking::Sockets::StreamSocket^ native_socket1 = nullptr;
  68. #else // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  69. int native_socket1 = ::socket(af_inet, sock_stream, 0);
  70. #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  71. sp::socket socket4(ios, sp(af_inet, ipproto_tcp), native_socket1);
  72. #if defined(BOOST_ASIO_HAS_MOVE)
  73. sp::socket socket5(std::move(socket4));
  74. boost::asio::ip::tcp::socket tcp_socket(ios);
  75. sp::socket socket6(std::move(tcp_socket));
  76. #endif // defined(BOOST_ASIO_HAS_MOVE)
  77. // basic_stream_socket operators.
  78. #if defined(BOOST_ASIO_HAS_MOVE)
  79. socket1 = sp::socket(ios);
  80. socket1 = std::move(socket2);
  81. socket1 = boost::asio::ip::tcp::socket(ios);
  82. #endif // defined(BOOST_ASIO_HAS_MOVE)
  83. // basic_io_object functions.
  84. io_service& ios_ref = socket1.get_io_service();
  85. (void)ios_ref;
  86. // basic_socket functions.
  87. sp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
  88. (void)lowest_layer;
  89. socket1.open(sp(af_inet, ipproto_tcp));
  90. socket1.open(sp(af_inet, ipproto_tcp), ec);
  91. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  92. Windows::Networking::Sockets::StreamSocket^ native_socket2 = nullptr;
  93. #else // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  94. int native_socket2 = ::socket(af_inet, sock_stream, 0);
  95. #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  96. socket1.assign(sp(af_inet, ipproto_tcp), native_socket2);
  97. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  98. Windows::Networking::Sockets::StreamSocket^ native_socket3 = nullptr;
  99. #else // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  100. int native_socket3 = ::socket(af_inet, sock_stream, 0);
  101. #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
  102. socket1.assign(sp(af_inet, ipproto_tcp), native_socket3, ec);
  103. bool is_open = socket1.is_open();
  104. (void)is_open;
  105. socket1.close();
  106. socket1.close(ec);
  107. sp::socket::native_type native_socket4 = socket1.native();
  108. (void)native_socket4;
  109. socket1.cancel();
  110. socket1.cancel(ec);
  111. bool at_mark1 = socket1.at_mark();
  112. (void)at_mark1;
  113. bool at_mark2 = socket1.at_mark(ec);
  114. (void)at_mark2;
  115. std::size_t available1 = socket1.available();
  116. (void)available1;
  117. std::size_t available2 = socket1.available(ec);
  118. (void)available2;
  119. socket1.bind(sp::endpoint());
  120. socket1.bind(sp::endpoint(), ec);
  121. socket1.connect(sp::endpoint());
  122. socket1.connect(sp::endpoint(), ec);
  123. socket1.async_connect(sp::endpoint(), connect_handler);
  124. socket1.set_option(socket_option);
  125. socket1.set_option(socket_option, ec);
  126. socket1.get_option(socket_option);
  127. socket1.get_option(socket_option, ec);
  128. socket1.io_control(io_control_command);
  129. socket1.io_control(io_control_command, ec);
  130. sp::endpoint endpoint1 = socket1.local_endpoint();
  131. sp::endpoint endpoint2 = socket1.local_endpoint(ec);
  132. sp::endpoint endpoint3 = socket1.remote_endpoint();
  133. sp::endpoint endpoint4 = socket1.remote_endpoint(ec);
  134. socket1.shutdown(socket_base::shutdown_both);
  135. socket1.shutdown(socket_base::shutdown_both, ec);
  136. // basic_stream_socket functions.
  137. socket1.send(buffer(mutable_char_buffer));
  138. socket1.send(buffer(const_char_buffer));
  139. socket1.send(null_buffers());
  140. socket1.send(buffer(mutable_char_buffer), in_flags);
  141. socket1.send(buffer(const_char_buffer), in_flags);
  142. socket1.send(null_buffers(), in_flags);
  143. socket1.send(buffer(mutable_char_buffer), in_flags, ec);
  144. socket1.send(buffer(const_char_buffer), in_flags, ec);
  145. socket1.send(null_buffers(), in_flags, ec);
  146. socket1.async_send(buffer(mutable_char_buffer), send_handler);
  147. socket1.async_send(buffer(const_char_buffer), send_handler);
  148. socket1.async_send(null_buffers(), send_handler);
  149. socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
  150. socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
  151. socket1.async_send(null_buffers(), in_flags, send_handler);
  152. socket1.receive(buffer(mutable_char_buffer));
  153. socket1.receive(null_buffers());
  154. socket1.receive(buffer(mutable_char_buffer), in_flags);
  155. socket1.receive(null_buffers(), in_flags);
  156. socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
  157. socket1.receive(null_buffers(), in_flags, ec);
  158. socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
  159. socket1.async_receive(null_buffers(), receive_handler);
  160. socket1.async_receive(buffer(mutable_char_buffer), in_flags,
  161. receive_handler);
  162. socket1.async_receive(null_buffers(), in_flags, receive_handler);
  163. socket1.write_some(buffer(mutable_char_buffer));
  164. socket1.write_some(buffer(const_char_buffer));
  165. socket1.write_some(null_buffers());
  166. socket1.write_some(buffer(mutable_char_buffer), ec);
  167. socket1.write_some(buffer(const_char_buffer), ec);
  168. socket1.write_some(null_buffers(), ec);
  169. socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler);
  170. socket1.async_write_some(buffer(const_char_buffer), write_some_handler);
  171. socket1.async_write_some(null_buffers(), write_some_handler);
  172. socket1.read_some(buffer(mutable_char_buffer));
  173. socket1.read_some(buffer(mutable_char_buffer), ec);
  174. socket1.read_some(null_buffers(), ec);
  175. socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
  176. socket1.async_read_some(null_buffers(), read_some_handler);
  177. }
  178. catch (std::exception&)
  179. {
  180. }
  181. }
  182. } // namespace generic_stream_protocol_socket_compile
  183. //------------------------------------------------------------------------------
  184. BOOST_ASIO_TEST_SUITE
  185. (
  186. "generic/stream_protocol",
  187. BOOST_ASIO_TEST_CASE(generic_stream_protocol_socket_compile::test)
  188. )