diff options
author | Machiavelli <none@none> | 2010-08-18 19:48:51 +0200 |
---|---|---|
committer | Machiavelli <none@none> | 2010-08-18 19:48:51 +0200 |
commit | d845a903b10b0788b03131a0cb1a2e72f55adc07 (patch) | |
tree | 44c8e0ea6ae88217167d05203378a3324572cee5 /src/server/shared/Database/SQLOperation.h | |
parent | 2ffe785765e3812e442d246f9561cebd83a008cb (diff) |
DBLayer:
- Use ACE_Future and ACE_Future_Set for async SQL queries with callback
* Callbacks will now be executed from the thread and object that scheduled the request, instead of the world runnable thread (and thus are no longer dependent on the 50ms forced sleep time).
* This design gets rid of a potential DOS loophole in the resultqueue system - unique requests will be cancelled when re-requested.
- Drop now redundant SQLQueryTask, SQLResultQueue, SQLResultQueueTask operations.
- Drop now redundant CharacterHandler class
- Change static callback functions in WorldSession to normal functions.
Thanks to Derex and Zor for advice along the way.
--HG--
branch : trunk
Diffstat (limited to 'src/server/shared/Database/SQLOperation.h')
-rw-r--r-- | src/server/shared/Database/SQLOperation.h | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/server/shared/Database/SQLOperation.h b/src/server/shared/Database/SQLOperation.h index 4833e28164e..0bf08d3e3eb 100644 --- a/src/server/shared/Database/SQLOperation.h +++ b/src/server/shared/Database/SQLOperation.h @@ -43,17 +43,21 @@ class SQLOperation : public ACE_Method_Request MySQLConnection* m_conn; }; +typedef ACE_Future<QueryResult_AutoPtr> QueryResultFuture; /*! Raw, ad-hoc query. */ class BasicStatementTask : public SQLOperation { public: BasicStatementTask(const char* sql); + BasicStatementTask(const char* sql, QueryResultFuture result); ~BasicStatementTask(); bool Execute(); private: const char* m_sql; //- Raw query to be executed + bool m_has_result; + QueryResultFuture m_result; }; /*! Transactions */ @@ -70,14 +74,6 @@ class TransactionTask : public SQLOperation std::queue<char*> m_queries; }; -/*! ResultQueue */ -class SQLResultQueue : public ACE_Based::LockedQueue<Trinity::IQueryCallback* , ACE_Thread_Mutex> -{ - public: - SQLResultQueue() {} - void Update(); -}; - class SQLQueryHolder { friend class SQLQueryHolderTask; @@ -94,28 +90,17 @@ class SQLQueryHolder void SetResult(size_t index, QueryResult_AutoPtr result); }; +typedef ACE_Future<SQLQueryHolder*> QueryResultHolderFuture; + class SQLQueryHolderTask : public SQLOperation { private: SQLQueryHolder * m_holder; - Trinity::IQueryCallback * m_callback; - SQLResultQueue * m_queue; - public: - SQLQueryHolderTask(SQLQueryHolder *holder, Trinity::IQueryCallback * callback, SQLResultQueue * queue) - : m_holder(holder), m_callback(callback), m_queue(queue) {} - bool Execute(); -}; + QueryResultHolderFuture m_result; -class SQLQueryTask : public SQLOperation -{ - private: - const char *m_sql; - Trinity::IQueryCallback * m_callback; - SQLResultQueue * m_queue; public: - SQLQueryTask(const char *sql, Trinity::IQueryCallback * callback, SQLResultQueue * queue) - : m_sql(strdup(sql)), m_callback(callback), m_queue(queue) {} - ~SQLQueryTask() { void* tofree = const_cast<char*>(m_sql); free(tofree); } + SQLQueryHolderTask(SQLQueryHolder *holder, QueryResultHolderFuture res) + : m_holder(holder), m_result(res){}; bool Execute(); }; |