| 28 | } |
| 29 | |
| 30 | void connection::do_read() |
| 31 | { |
| 32 | auto self(shared_from_this()); |
| 33 | socket_.async_read_some(boost::asio::buffer(buffer_), |
| 34 | [this, self](boost::system::error_code ec, std::size_t bytes_transferred) |
| 35 | { |
| 36 | if (!ec) |
| 37 | { |
| 38 | request_parser::result_type result; |
| 39 | std::tie(result, std::ignore) = request_parser_.parse( |
| 40 | request_, buffer_.data(), buffer_.data() + bytes_transferred); |
| 41 | |
| 42 | if (result == request_parser::good) |
| 43 | { |
| 44 | request_handler_.handle_request(request_, reply_); |
| 45 | do_write(); |
| 46 | } |
| 47 | else if (result == request_parser::bad) |
| 48 | { |
| 49 | reply_ = reply::stock_reply(reply::bad_request); |
| 50 | do_write(); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | do_read(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // If an error occurs then no new asynchronous operations are |
| 59 | // started. This means that all shared_ptr references to the |
| 60 | // connection object will disappear and the object will be |
| 61 | // destroyed automatically after this handler returns. The |
| 62 | // connection class's destructor closes the socket. |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | void connection::do_write() |
| 67 | { |
nothing calls this directly
no test coverage detected