MCPcopy Create free account
hub / github.com/boostorg/beast / testWrite

Method testWrite

test/beast/core/basic_stream.cpp:588–679  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586 }
587
588 void
589 testWrite()
590 {
591 using stream_type = basic_stream<tcp,
592 net::io_context::executor_type>;
593
594 char buf[4];
595 net::io_context ioc;
596 std::memset(buf, 0, sizeof(buf));
597 net::const_buffer cb(buf, sizeof(buf));
598 auto const ep = net::ip::tcp::endpoint(
599 net::ip::make_address("127.0.0.1"), 0);
600
601 // write_some
602
603 {
604 error_code ec;
605 stream_type s(ioc, tcp::v4());
606 BEAST_EXPECT(s.write_some(net::const_buffer{}) == 0);
607 BEAST_EXPECT(s.write_some(net::const_buffer{}, ec) == 0);
608 BEAST_EXPECTS(! ec, ec.message());
609 }
610
611 // async_write_some
612
613 {
614 // success
615 test_server srv("*", ep, log);
616 stream_type s(ioc);
617 s.socket().connect(srv.local_endpoint());
618 s.expires_never();
619 s.async_write_some(cb, handler({}, 4));
620 ioc.run();
621 ioc.restart();
622 }
623
624 {
625 // success, with timeout
626 test_server srv("*", ep, log);
627 stream_type s(ioc);
628 s.socket().connect(srv.local_endpoint());
629 s.expires_after(std::chrono::seconds(30));
630 s.async_write_some(cb, handler({}, 4));
631 ioc.run();
632 ioc.restart();
633 }
634
635 {
636 // empty buffer
637 test_server srv("*", ep, log);
638 stream_type s(ioc);
639 s.socket().connect(srv.local_endpoint());
640 s.expires_never();
641 s.async_write_some(
642 net::const_buffer{}, handler({}, 0));
643 ioc.run();
644 ioc.restart();
645 }

Callers

nothing calls this directly

Calls 6

messageMethod · 0.80
local_endpointMethod · 0.80
async_write_someMethod · 0.80
handlerClass · 0.70
write_someMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected