From b23255389ff1ab1ad3f17623200526c0ad745df1 Mon Sep 17 00:00:00 2001 From: badaix Date: Sat, 2 May 2020 14:25:55 +0200 Subject: [PATCH] Fix server crash if client crashes during connect --- server/stream_session.cpp | 13 +++++++++++++ server/stream_session.hpp | 5 +---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/stream_session.cpp b/server/stream_session.cpp index b9307a3c..35c2cfc7 100644 --- a/server/stream_session.cpp +++ b/server/stream_session.cpp @@ -43,6 +43,19 @@ StreamSession::~StreamSession() } +std::string StreamSession::getIP() +{ + try + { + return socket_.remote_endpoint().address().to_string(); + } + catch (...) + { + return "0.0.0.0"; + } +} + + void StreamSession::read_next() { boost::asio::async_read(socket_, boost::asio::buffer(buffer_, base_msg_size_), diff --git a/server/stream_session.hpp b/server/stream_session.hpp index c31508fb..8d3f42d8 100644 --- a/server/stream_session.hpp +++ b/server/stream_session.hpp @@ -128,10 +128,7 @@ public: std::string clientId; - std::string getIP() - { - return socket_.remote_endpoint().address().to_string(); - } + std::string getIP(); void setPcmStream(streamreader::PcmStreamPtr pcmStream); const streamreader::PcmStreamPtr pcmStream() const;