diff --git a/Common/Cpp/Sockets/AbstractClientSocket.h b/Common/Cpp/Sockets/AbstractClientSocket.h index 1c328ddad5..301f88c40c 100644 --- a/Common/Cpp/Sockets/AbstractClientSocket.h +++ b/Common/Cpp/Sockets/AbstractClientSocket.h @@ -35,6 +35,11 @@ class AbstractClientSocket{ // Called when the socket receives data from the server. virtual void on_receive_data(const void* data, size_t bytes){} + + // Called when an established connection is lost (the server closed + // the connection or a socket error occurred). It is not called by + // "close()". + virtual void on_disconnect(const std::string& error_message){} }; void add_listener(Listener& listener){ diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp index d536ec641e..5348de011d 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp @@ -151,7 +151,7 @@ void TcpSysbotBase_Connection::thread_loop(){ void TcpSysbotBase_Connection::on_connect_finished(const std::string& error_message){ try{ if (!error_message.empty()){ - m_logger.log(m_connecting_message, COLOR_RED); + m_logger.log(m_connecting_message + " - " + error_message, COLOR_RED); set_status_line0(m_connecting_message, COLOR_RED); return; } @@ -162,6 +162,12 @@ void TcpSysbotBase_Connection::on_connect_finished(const std::string& error_mess write_data("getVersion\r\n"); }catch (...){} } +void TcpSysbotBase_Connection::on_disconnect(const std::string& error_message){ + try{ + m_logger.log("sys-botbase disconnected: " + error_message, COLOR_RED); + set_status_line1("Disconnected: " + error_message, COLOR_RED); + }catch (...){} +} void TcpSysbotBase_Connection::on_receive_data(const void* data, size_t bytes){ // cout << "on_receive_data(): " << std::string((const char*)data, bytes - 2) << endl; diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h index 550ab82fed..e3b5b5b9dc 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h @@ -49,6 +49,7 @@ class TcpSysbotBase_Connection : public ControllerConnection, private ClientSock virtual void on_connect_finished(const std::string& error_message) override; virtual void on_receive_data(const void* data, size_t bytes) override; + virtual void on_disconnect(const std::string& error_message) override; void process_message(const std::string& message, WallClock timestamp); void set_mode(const std::string& sbb_version);