diff options
author | Michael Maroszek <maroszek@gmx.net> | 2020-07-28 17:38:18 +0300 |
---|---|---|
committer | Michael Maroszek <maroszek@gmx.net> | 2020-07-28 17:38:18 +0300 |
commit | 95cefd438f06dab3ef2c501c0d1f1105121ce305 (patch) | |
tree | e8e05f5d51b3bf6e099ee6a6603359499d193351 | |
parent | af45eb04b86718eac820ba8a3e781d8044ce3de1 (diff) |
move endpoint initialization further up
-rw-r--r-- | server_ws.hpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/server_ws.hpp b/server_ws.hpp index 955975c..6af4384 100644 --- a/server_ws.hpp +++ b/server_ws.hpp @@ -79,13 +79,7 @@ namespace SimpleWeb { friend class SocketServer<socket_type>; public: - Connection(std::unique_ptr<socket_type> &&socket_) noexcept : socket(std::move(socket_)), timeout_idle(0), closed(false) { - try { - endpoint = socket->lowest_layer().remote_endpoint(); - } - catch (...) { - } - } + Connection(std::unique_ptr<socket_type> &&socket_) noexcept : socket(std::move(socket_)), timeout_idle(0), closed(false) {} std::string method, path, query_string, http_version; @@ -121,13 +115,7 @@ namespace SimpleWeb { /// Used to call Server::upgrade. template <typename... Args> Connection(std::shared_ptr<ScopeRunner> handler_runner_, long timeout_idle, Args &&... args) noexcept - : handler_runner(std::move(handler_runner_)), socket(new socket_type(std::forward<Args>(args)...)), timeout_idle(timeout_idle), closed(false) { - try { - endpoint = socket->lowest_layer().remote_endpoint(); - } - catch (...) { - } - } + : handler_runner(std::move(handler_runner_)), socket(new socket_type(std::forward<Args>(args)...)), timeout_idle(timeout_idle), closed(false) {} std::shared_ptr<ScopeRunner> handler_runner; @@ -542,6 +530,12 @@ namespace SimpleWeb { } void write_handshake(const std::shared_ptr<Connection> &connection) { + try { + connection->endpoint = connection->socket->lowest_layer().remote_endpoint(); + } + catch (...) { + } + for(auto ®ex_endpoint : endpoint) { regex::smatch path_match; if(regex::regex_match(connection->path, path_match, regex_endpoint.first)) { |