Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct socket_pair
- {
- net::io_context ioc1;
- net::ip::tcp::socket s1;
- net::io_context ioc2;
- net::ip::tcp::socket s2;
- socket_pair()
- : s1(ioc1)
- , s2(ioc2)
- {
- net::io_context ioc;
- net::ip::tcp::acceptor a(ioc);
- net::ip::tcp::endpoint ep(
- net::ip::make_address_v4("127.0.0.1"), 0);
- a.open(ep.protocol());
- a.set_option(
- net::socket_base::reuse_address(true));
- a.bind(ep);
- a.listen(
- net::socket_base::max_listen_connections);
- a.async_accept(s2,
- [](error_code ec)
- {
- if(ec)
- BOOST_THROW_EXCEPTION(system_error{ec});
- });
- s1.async_connect(a.local_endpoint(),
- [](error_code ec)
- {
- if(ec)
- BOOST_THROW_EXCEPTION(system_error{ec});
- });
- for(;;)
- if(
- ioc.poll() +
- ioc1.poll() +
- ioc2.poll() == 0)
- break;
- BOOST_ASSERT(s1.is_open());
- BOOST_ASSERT(s2.is_open());
- BOOST_ASSERT(
- s1.remote_endpoint() ==
- s2.local_endpoint());
- BOOST_ASSERT(
- s2.remote_endpoint() ==
- s1.local_endpoint());
- }
- };
Add Comment
Please, Sign In to add comment