From eafca19cb33dbf3f220144db067b5c458e9460b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 3 Sep 2016 18:15:57 +0200 Subject: [PATCH] feature: move exception handling of read_remote_endpoint_data to calling method --- server_http.hpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/server_http.hpp b/server_http.hpp index 70a86a2..ea75582 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -80,21 +80,14 @@ namespace SimpleWeb { std::string remote_endpoint_address; unsigned short remote_endpoint_port; - std::function exception_handler; private: Request(): content(streambuf) {} boost::asio::streambuf streambuf; void read_remote_endpoint_data(socket_type& socket) { - try { - remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string(); - remote_endpoint_port=socket.lowest_layer().remote_endpoint().port(); - } - catch(const std::exception&e) { - if(exception_handler) - exception_handler(e); - } + remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string(); + remote_endpoint_port=socket.lowest_layer().remote_endpoint().port(); } }; @@ -223,7 +216,13 @@ namespace SimpleWeb { //Create new streambuf (Request::streambuf) for async_read_until() //shared_ptr is used to pass temporary objects to the asynchronous functions std::shared_ptr request(new Request()); - request->read_remote_endpoint_data(*socket); + try { + request->read_remote_endpoint_data(*socket); + } + catch(const std::exception &e) { + if(exception_handler) + exception_handler(e); + } //Set timeout on the following boost::asio::async-read or write function std::shared_ptr timer; @@ -383,7 +382,7 @@ namespace SimpleWeb { try { resource_function(response, request); } - catch(const std::exception&e) { + catch(const std::exception &e) { if(exception_handler) exception_handler(e); return;