diff options
author | DDuarte <dnpd.dd@gmail.com> | 2014-07-28 02:56:56 +0100 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2014-07-28 02:58:03 +0100 |
commit | 100fd82b2bf5b9254db5ad13656ed4f148f858b2 (patch) | |
tree | b3d33fa025f9af75c95afe253f0f49c6b08621e1 | |
parent | a15c8af994446b2ae568117e21bc1747d1cf4c89 (diff) |
Core/Networking: Attempt to fix some exceptions
Call the non-throwing versions of socket.remote_endpoint in GetRemoteIpAddress
and GetRemotePort. Sh*t will still be broken tho
-rw-r--r-- | src/server/shared/Networking/Socket.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h index 9c3ec180b0a..059de140797 100644 --- a/src/server/shared/Networking/Socket.h +++ b/src/server/shared/Networking/Socket.h @@ -39,8 +39,33 @@ public: virtual void Start() = 0; - boost::asio::ip::address GetRemoteIpAddress() const { return _socket.remote_endpoint().address(); }; - uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); } + boost::asio::ip::address GetRemoteIpAddress() const + { + boost::system::error_code error; + auto ep = _socket.remote_endpoint(error); + + if (error) + { + TC_LOG_DEBUG("network", "Socket::GetRemoteIpAddress: errored with: %i (%s)", error.value(), error.message().c_str()); + return boost::asio::ip::address(); + } + else + return ep.address(); + } + + uint16 GetRemotePort() const + { + boost::system::error_code error; + auto ep = _socket.remote_endpoint(error); + + if (error) + { + TC_LOG_DEBUG("network", "Socket::GetRemotePort: errored with: %i (%s)", error.value(), error.message().c_str()); + return 0; + } + else + return ep.port(); + } void AsyncReadHeader() { |