@@ -39,16 +39,24 @@ class PerfdataWriterTargetFixture
3939 explicit PerfdataWriterTargetFixture (AsioTlsOrTcpStream stream)
4040 : m_Stream(std::move(stream)),
4141 m_Acceptor(
42- IoEngine::Get ().GetIoContext(),
43- boost::asio::ip::tcp::endpoint{boost::asio::ip::address_v4::loopback (), 0 }
42+ IoEngine::Get ().GetIoContext()
4443 )
4544 {
45+ boost::asio::ip::tcp::endpoint ep{boost::asio::ip::address_v4::loopback (), 0 };
46+ m_Acceptor.open (ep.protocol ());
47+ m_Acceptor.bind (ep);
4648 }
4749
4850 unsigned short GetPort () { return m_Acceptor.local_endpoint ().port (); }
4951
52+ void Listen ()
53+ {
54+ m_Acceptor.listen ();
55+ }
56+
5057 void Accept ()
5158 {
59+ Listen ();
5260 BOOST_REQUIRE_NO_THROW (
5361 std::visit ([&](auto & stream) { return m_Acceptor.accept (stream->lowest_layer ()); }, m_Stream)
5462 );
@@ -63,11 +71,20 @@ class PerfdataWriterTargetFixture
6371 BOOST_REQUIRE (stream->next_layer ().IsVerifyOK ());
6472 }
6573
66- void Shutdown ()
74+ void Shutdown (bool wait = false )
6775 {
6876 BOOST_REQUIRE (std::holds_alternative<Shared<AsioTlsStream>::Ptr>(m_Stream));
6977 auto & stream = std::get<Shared<AsioTlsStream>::Ptr>(m_Stream);
7078 try {
79+ if (wait) {
80+ std::array<std::byte, 128 > buf{};
81+ boost::asio::mutable_buffer readBuf (buf.data (), buf.size ());
82+ boost::system::error_code ec;
83+
84+ do {
85+ stream->read_some (readBuf, ec);
86+ } while (!ec);
87+ }
7188 stream->next_layer ().shutdown ();
7289 } catch (const std::exception& ex) {
7390 if (const auto * se = dynamic_cast <const boost::system::system_error*>(&ex);
0 commit comments