| 20 | using asio::ip::tcp; |
| 21 | |
| 22 | void session(tcp::socket sock) { |
| 23 | int msg_index = 0; |
| 24 | for (;;) { |
| 25 | const size_t max_length = 1024; |
| 26 | char data[max_length]; |
| 27 | auto [error, length] = read_some(sock, asio::buffer(data, max_length)); |
| 28 | msg_index++; |
| 29 | if (error == asio::error::eof) { |
| 30 | std::cout << "Remote client closed at message index: " |
| 31 | << msg_index - 1 << ".\n"; |
| 32 | break; |
| 33 | } else if (error) { |
| 34 | std::cout << error.message() << '\n'; |
| 35 | throw asio::system_error(error); |
| 36 | } |
| 37 | |
| 38 | write(sock, asio::buffer(data, length)); |
| 39 | } |
| 40 | std::cout << "Finished echo message, total: " << msg_index - 1 << ".\n"; |
| 41 | } |
| 42 | |
| 43 | void start_server(asio::io_context& io_context, unsigned short port) { |
| 44 | tcp::acceptor a(io_context, tcp::endpoint(tcp::v4(), port)); |
no test coverage detected