From 100fd82b2bf5b9254db5ad13656ed4f148f858b2 Mon Sep 17 00:00:00 2001 From: DDuarte Date: Mon, 28 Jul 2014 02:56:56 +0100 Subject: 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 --- src/server/shared/Networking/Socket.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') 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() { -- cgit v1.2.3