# HG changeset patch # User Teemu Piippo # Date 1418690898 -7200 # Node ID d175243ad1692a714c9c6ebd5f84be0aabf97290 # Parent a2f41245e387b27873107e770b3aec2c3ef45ff9 - rcon sessions are no longer allocated on the heap diff -r a2f41245e387 -r d175243ad169 sources/interface.cpp --- a/sources/interface.cpp Tue Dec 16 02:30:31 2014 +0200 +++ b/sources/interface.cpp Tue Dec 16 02:48:18 2014 +0200 @@ -830,7 +830,8 @@ case INPUTSTATE_PASSWORD: if (g_inputState == INPUTSTATE_PASSWORD and not current_input().is_empty()) { - RCONSession* session = RCONSession::new_session(); + RCONSession* session = RCONSession::get_session(); + session->disconnect(); session->set_password (current_input()); session->connect (g_address); set_input_state (INPUTSTATE_NORMAL); @@ -963,7 +964,8 @@ if (g_address.port == 0) g_address.port = 10666; - RCONSession* session = RCONSession::new_session(); + RCONSession* session = RCONSession::get_session(); + session->disconnect(); session->set_password (password); session->connect (g_address); } diff -r a2f41245e387 -r d175243ad169 sources/main.cpp --- a/sources/main.cpp Tue Dec 16 02:30:31 2014 +0200 +++ b/sources/main.cpp Tue Dec 16 02:48:18 2014 +0200 @@ -49,7 +49,6 @@ } Interface::initialize(); - RCONSession::new_session(); if (argc == 3) Interface::connect (argv[1], argv[2]); diff -r a2f41245e387 -r d175243ad169 sources/network/bytestream.cpp --- a/sources/network/bytestream.cpp Tue Dec 16 02:30:31 2014 +0200 +++ b/sources/network/bytestream.cpp Tue Dec 16 02:48:18 2014 +0200 @@ -68,7 +68,7 @@ // Bytestream::~Bytestream() { - delete m_data; + delete[] m_data; } // ------------------------------------------------------------------------------------------------- diff -r a2f41245e387 -r d175243ad169 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Tue Dec 16 02:30:31 2014 +0200 +++ b/sources/network/rconsession.cpp Tue Dec 16 02:48:18 2014 +0200 @@ -1,48 +1,24 @@ #include "rconsession.h" #include "../interface.h" -RCONSession* g_rconSession = nullptr; - // ------------------------------------------------------------------------------------------------- // RCONSession::RCONSession() : m_state (RCON_DISCONNECTED), m_lastPing (0), - m_numAdmins (0) {} - -// ------------------------------------------------------------------------------------------------- -// -STATIC METHOD -RCONSession::new_session() -> RCONSession* + m_numAdmins (0) { - if (g_rconSession != NULL) + if (not m_socket.set_blocking (false)) { - g_rconSession->disconnect(); - delete g_rconSession; + print_to (stderr, "unable to set socket as non-blocking: %s\n", + m_socket.error_string().chars()); + exit (EXIT_FAILURE); } - - g_rconSession = new RCONSession; - - if (not g_rconSession->socket()->set_blocking (false)) - { - print ("unable to set socket as non-blocking: %s\n", - g_rconSession->socket()->error_string().chars()); - delete g_rconSession; - return nullptr; - } - - return g_rconSession; } // ------------------------------------------------------------------------------------------------- // -RCONSession::~RCONSession() -{ - disconnect(); - - if (g_rconSession == this) - g_rconSession = nullptr; -} +RCONSession::~RCONSession() {} // ------------------------------------------------------------------------------------------------- // @@ -279,10 +255,8 @@ STATIC METHOD RCONSession::get_session() -> RCONSession* { - if (g_rconSession == nullptr) - new_session(); - - return g_rconSession; + static RCONSession session; + return &session; } // ------------------------------------------------------------------------------------------------- diff -r a2f41245e387 -r d175243ad169 sources/network/rconsession.h --- a/sources/network/rconsession.h Tue Dec 16 02:30:31 2014 +0200 +++ b/sources/network/rconsession.h Tue Dec 16 02:48:18 2014 +0200 @@ -108,7 +108,6 @@ METHOD level() const -> const String&; METHOD is_active() const -> bool; - static METHOD new_session() -> RCONSession*; static METHOD get_session() -> RCONSession*; private: