aboutsummaryrefslogtreecommitdiff
path: root/src/server/database/Database/MySQLConnection.h
diff options
context:
space:
mode:
authorNaios <naios-dev@live.de>2016-03-03 01:19:58 +0100
committerNaios <naios-dev@live.de>2016-03-03 01:51:50 +0100
commitd0263c03fd7cc7291b2eed2a3ca027cf1a8926e2 (patch)
treea26d0405ee27147e2527dd64d388f9cd346d128b /src/server/database/Database/MySQLConnection.h
parent31c8f9a7ed9acee9a02be690bfb70a820f9c53e8 (diff)
Core/Database: Use RAII for resource management in MySQLConnection
* Prevents double deletion of MySQLConnection after errors * The object stays valid after an error and will wait for a reconnect * Also crash the server if 5 reconnects fail * Corrects an issue where the server was crashed after one reconnect because mysql_thread_id was invoked with an invalid handle (cherry picked from commit 62815c6e1c0427e1d0229d02b1ba70449654cded)
Diffstat (limited to 'src/server/database/Database/MySQLConnection.h')
-rw-r--r--src/server/database/Database/MySQLConnection.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/server/database/Database/MySQLConnection.h b/src/server/database/Database/MySQLConnection.h
index a981caa607e..a0b908593df 100644
--- a/src/server/database/Database/MySQLConnection.h
+++ b/src/server/database/Database/MySQLConnection.h
@@ -116,18 +116,18 @@ class MySQLConnection
virtual void DoPrepareStatements() = 0;
protected:
- std::vector<MySQLPreparedStatement*> m_stmts; //! PreparedStatements storage
+ std::vector<std::unique_ptr<MySQLPreparedStatement>> m_stmts; //! PreparedStatements storage
PreparedStatementMap m_queries; //! Query storage
bool m_reconnecting; //! Are we reconnecting?
bool m_prepareError; //! Was there any error while preparing statements?
private:
- bool _HandleMySQLErrno(uint32 errNo);
+ bool _HandleMySQLErrno(uint32 errNo, uint8 attempts = 5);
private:
ProducerConsumerQueue<SQLOperation*>* m_queue; //! Queue shared with other asynchronous connections.
- DatabaseWorker* m_worker; //! Core worker task.
- MYSQL * m_Mysql; //! MySQL Handle.
+ std::unique_ptr<DatabaseWorker> m_worker; //! Core worker task.
+ MYSQL* m_Mysql; //! MySQL Handle.
MySQLConnectionInfo& m_connectionInfo; //! Connection info (used for logging)
ConnectionFlags m_connectionFlags; //! Connection flags (for preparing relevant statements)
std::mutex m_Mutex;