MCPcopy Create free account
hub / github.com/boostorg/asio / go

Method go

example/cpp11/spawn/echo_server.cpp:32–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 }
31
32 void go()
33 {
34 auto self(shared_from_this());
35 boost::asio::spawn(strand_,
36 [this, self](boost::asio::yield_context yield)
37 {
38 try
39 {
40 char data[128];
41 for (;;)
42 {
43 timer_.expires_after(std::chrono::seconds(10));
44 std::size_t n = socket_.async_read_some(boost::asio::buffer(data), yield);
45 boost::asio::async_write(socket_, boost::asio::buffer(data, n), yield);
46 }
47 }
48 catch (std::exception& e)
49 {
50 socket_.close();
51 timer_.cancel();
52 }
53 }, boost::asio::detached);
54
55 boost::asio::spawn(strand_,
56 [this, self](boost::asio::yield_context yield)
57 {
58 while (socket_.is_open())
59 {
60 boost::system::error_code ignored_ec;
61 timer_.async_wait(yield[ignored_ec]);
62 if (timer_.expiry() <= boost::asio::steady_timer::clock_type::now())
63 socket_.close();
64 }
65 }, boost::asio::detached);
66 }
67
68private:
69 tcp::socket socket_;

Callers 1

mainFunction · 0.80

Calls 11

spawnFunction · 0.85
bufferFunction · 0.85
async_writeFunction · 0.85
nowFunction · 0.50
expires_afterMethod · 0.45
async_read_someMethod · 0.45
closeMethod · 0.45
cancelMethod · 0.45
is_openMethod · 0.45
async_waitMethod · 0.45
expiryMethod · 0.45

Tested by

no test coverage detected