aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Database/SQLOperation.cpp
diff options
context:
space:
mode:
authorMachiavelli <none@none>2010-08-18 19:48:51 +0200
committerMachiavelli <none@none>2010-08-18 19:48:51 +0200
commitd845a903b10b0788b03131a0cb1a2e72f55adc07 (patch)
tree44c8e0ea6ae88217167d05203378a3324572cee5 /src/server/shared/Database/SQLOperation.cpp
parent2ffe785765e3812e442d246f9561cebd83a008cb (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.cpp')
-rw-r--r--src/server/shared/Database/SQLOperation.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/server/shared/Database/SQLOperation.cpp b/src/server/shared/Database/SQLOperation.cpp
index c9e3ba3e937..35a61dc9518 100644
--- a/src/server/shared/Database/SQLOperation.cpp
+++ b/src/server/shared/Database/SQLOperation.cpp
@@ -21,7 +21,15 @@
#include "Log.h"
/*! Basic, ad-hoc queries. */
-BasicStatementTask::BasicStatementTask(const char* sql)
+BasicStatementTask::BasicStatementTask(const char* sql) :
+m_has_result(false)
+{
+ m_sql = strdup(sql);
+}
+
+BasicStatementTask::BasicStatementTask(const char* sql, QueryResultFuture result) :
+m_result(result),
+m_has_result(true)
{
m_sql = strdup(sql);
}
@@ -33,6 +41,15 @@ BasicStatementTask::~BasicStatementTask()
bool BasicStatementTask::Execute()
{
+ if (m_has_result)
+ {
+ m_result.set(
+ m_conn->Query(m_sql)
+ );
+
+ return true;
+ }
+
return m_conn->Execute(m_sql);
}
@@ -83,18 +100,6 @@ bool TransactionTask::Execute()
return true;
}
-/*! Callback statements/holders */
-void SQLResultQueue::Update()
-{
- /// execute the callbacks waiting in the synchronization queue
- Trinity::IQueryCallback* callback;
- while (next(callback))
- {
- callback->Execute();
- delete callback;
- }
-}
-
bool SQLQueryHolder::SetQuery(size_t index, const char *sql)
{
if (m_queries.size() <= index)
@@ -181,7 +186,7 @@ void SQLQueryHolder::SetSize(size_t size)
bool SQLQueryHolderTask::Execute()
{
- if (!m_holder || !m_callback || !m_queue)
+ if (!m_holder)
return false;
/// we can do this, we are friends
@@ -195,19 +200,6 @@ bool SQLQueryHolderTask::Execute()
m_holder->SetResult(i, m_conn->Query(sql));
}
- /// sync with the caller thread
- m_queue->add(m_callback);
- return true;
-}
-
-bool SQLQueryTask::Execute()
-{
- if (!m_callback || !m_queue)
- return false;
-
- /// execute the query and store the result in the callback
- m_callback->SetResult(m_conn->Query(m_sql));
- /// add the callback to the sql result queue of the thread it originated from
- m_queue->add(m_callback);
+ m_result.set(m_holder);
return true;
}