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

Function session

example/cpp11/echo/blocking_tcp_echo_server.cpp:21–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19const int max_length = 1024;
20
21void session(tcp::socket sock)
22{
23 try
24 {
25 for (;;)
26 {
27 char data[max_length];
28
29 boost::system::error_code error;
30 size_t length = sock.read_some(boost::asio::buffer(data), error);
31 if (error == boost::asio::error::eof)
32 break; // Connection closed cleanly by peer.
33 else if (error)
34 throw boost::system::system_error(error); // Some other error.
35
36 boost::asio::write(sock, boost::asio::buffer(data, length));
37 }
38 }
39 catch (std::exception& e)
40 {
41 std::cerr << "Exception in thread: " << e.what() << "\n";
42 }
43}
44
45void server(boost::asio::io_context& io_context, unsigned short port)
46{

Callers

nothing calls this directly

Calls 3

bufferFunction · 0.85
writeFunction · 0.85
read_someMethod · 0.45

Tested by

no test coverage detected