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

Function session

example/cpp14/echo/blocking_tcp_echo_server.cpp:22–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

bufferFunction · 0.85
writeFunction · 0.85
read_someMethod · 0.45

Tested by

no test coverage detected