22#include " catch.hpp"
33#include < boost/asio/io_context.hpp>
44#include < boost/asio/ip/tcp.hpp>
5+ #include < boost/asio/ip/udp.hpp>
6+ #include < boost/asio/ip/v6_only.hpp>
57#include < chrono>
68#include < condition_variable>
79#include < future>
@@ -62,7 +64,7 @@ template <typename T> void test_cancel_thread(T &&task, cancellable_streambuf &s
6264 }
6365}
6466
65- TEST_CASE (" streambufs can connect" , " [streambuf][basic]" ) {
67+ TEST_CASE (" streambufs can connect" , " [streambuf][basic][network] " ) {
6668 asio::io_context io_ctx;
6769 cancellable_streambuf sb_connect;
6870 INFO (" Thread 0: Binding remote socket and keeping it busy…" )
@@ -93,7 +95,7 @@ TEST_CASE("streambufs can connect", "[streambuf][basic]") {
9395 remote.close ();
9496}
9597
96- TEST_CASE (" streambufs can transfer data" , " [streambuf][read ]" ) {
98+ TEST_CASE (" streambufs can transfer data" , " [streambuf][network ]" ) {
9799 asio::io_context io_ctx;
98100 cancellable_streambuf sb_read;
99101 ip::tcp::endpoint ep (ip::address_v4::loopback (), port + 1 );
@@ -108,7 +110,30 @@ TEST_CASE("streambufs can transfer data", "[streambuf][read]") {
108110 test_cancel_thread (
109111 [&sb_read]() {
110112 int c = sb_read.sgetc ();
111- MINFO (" Thread 1: Read char " << c);
113+ MINFO (" Thread 1: Read char " << c)
112114 },
113115 sb_read);
114116}
117+
118+ TEST_CASE (" receive v4 packets on v6 socket" , " [ipv6][network]" ) {
119+ const uint16_t test_port = port + 2 ;
120+ asio::io_context io_ctx;
121+ ip::udp::socket sock (io_ctx, ip::udp::v6 ());
122+ sock.set_option (ip::v6_only (false ));
123+ sock.bind (ip::udp::endpoint (ip::address_v6::any (), test_port));
124+
125+ ip::udp::socket sender_v4 (io_ctx, ip::udp::v4 ()), sender_v6 (io_ctx, ip::udp::v6 ());
126+ const std::string buf = " Hello World" ;
127+ asio::const_buffer sbuf (buf.data (), buf.length ());
128+ char recvbuf[64 ] = {0 };
129+ sender_v4.send_to (sbuf, ip::udp::endpoint (ip::address_v4::loopback (), test_port));
130+ auto recv_len = sock.receive (asio::buffer (recvbuf, sizeof (recvbuf) - 1 ));
131+ CHECK (recv_len == buf.length ());
132+ CHECK (buf == recvbuf);
133+ std::fill_n (recvbuf, recv_len, 0 );
134+
135+ sender_v6.send_to (sbuf, ip::udp::endpoint (ip::address_v6::loopback (), test_port));
136+ recv_len = sock.receive (asio::buffer (recvbuf, sizeof (recvbuf) - 1 ));
137+ CHECK (buf == recvbuf);
138+ std::fill_n (recvbuf, recv_len, 0 );
139+ }
0 commit comments