feature: move exception handling of read_remote_endpoint_data to calling method
This commit is contained in:
parent
d490c3ff4e
commit
eafca19cb3
1 changed files with 10 additions and 11 deletions
|
|
@ -80,21 +80,14 @@ namespace SimpleWeb {
|
||||||
std::string remote_endpoint_address;
|
std::string remote_endpoint_address;
|
||||||
unsigned short remote_endpoint_port;
|
unsigned short remote_endpoint_port;
|
||||||
|
|
||||||
std::function<void(const std::exception&)> exception_handler;
|
|
||||||
private:
|
private:
|
||||||
Request(): content(streambuf) {}
|
Request(): content(streambuf) {}
|
||||||
|
|
||||||
boost::asio::streambuf streambuf;
|
boost::asio::streambuf streambuf;
|
||||||
|
|
||||||
void read_remote_endpoint_data(socket_type& socket) {
|
void read_remote_endpoint_data(socket_type& socket) {
|
||||||
try {
|
remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string();
|
||||||
remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string();
|
remote_endpoint_port=socket.lowest_layer().remote_endpoint().port();
|
||||||
remote_endpoint_port=socket.lowest_layer().remote_endpoint().port();
|
|
||||||
}
|
|
||||||
catch(const std::exception&e) {
|
|
||||||
if(exception_handler)
|
|
||||||
exception_handler(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -223,7 +216,13 @@ namespace SimpleWeb {
|
||||||
//Create new streambuf (Request::streambuf) for async_read_until()
|
//Create new streambuf (Request::streambuf) for async_read_until()
|
||||||
//shared_ptr is used to pass temporary objects to the asynchronous functions
|
//shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||||
std::shared_ptr<Request> request(new Request());
|
std::shared_ptr<Request> 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
|
//Set timeout on the following boost::asio::async-read or write function
|
||||||
std::shared_ptr<boost::asio::deadline_timer> timer;
|
std::shared_ptr<boost::asio::deadline_timer> timer;
|
||||||
|
|
@ -383,7 +382,7 @@ namespace SimpleWeb {
|
||||||
try {
|
try {
|
||||||
resource_function(response, request);
|
resource_function(response, request);
|
||||||
}
|
}
|
||||||
catch(const std::exception&e) {
|
catch(const std::exception &e) {
|
||||||
if(exception_handler)
|
if(exception_handler)
|
||||||
exception_handler(e);
|
exception_handler(e);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue