CDatabase::Result theResult;HANDLE h = CDatabase::Get().RequestUser("Steve");while(!CDatabase::Get().OperationComplete(h,theResult)){ if(Something()) { CDatabase::Get().Abort(h); return; } Sleep(10);}if(theResult.nErrorCode != 0){ // Handle MySQL error return;}User* pUser = (User*)theResult.pBuffer;// Do stuff to pUser hereCDatabase::Get().FreeResult(theResult);
If you call CDatabase::Abort(), the database looks through it's list of pending events, and if it's there, just removes the event so the worker thread never picks it up. If it's not still to be processed, it checks if it's already been processed and removes it if it is. Otherwise, the worker thread is processing it, so it records the event handle as needing rechecked, and in CDatabase::OperationComplete(), if there's an event to be checked, it'll see if that event has been processed, and if it has, it'll remove it from the output queue.
It works perfectly, despite sounding horrible [smile]
I also did a bit of testing and removed a couple of bugs. I still need to do some proper bug testing though; most of it'll require me asking people to try and exploit my code (cause buffer overruns, try to do something when the server isn't ready [E.g. ask for a character list before the user is logged in] and the like).
I also still need to check if the user is already logged in when they try to log on, and kick the connected one if they are. I'll probably leave that till after the test, since that means I don't need to have unique users for everything, and testers can use a few characters.
Tomorrow is my last day at PC World. Yay! Nothing that special actually, since I still need to go back in to return my uniform, and it's the closest PC shop, so I'll still go for getting blank CDs / DVDs, ink cartriges, etc.
I'd like to get set up TEH MMORPG!!1 for user testing tomorrow evening, and have it ready to go on Friday / weekend, but I don't know if I'll have time. I need an early night, since I have to be up at 9am instead of 1pm, which I've done for the past couple of days (Working 2 - 8).
Anyway, South Park, then bed.