curl-library
Message Queueing
Date: Fri, 2 May 2003 17:40:55 -0600
Hey all,
This is not directly cURL related, but I figured this would be the best place to get awnsers so thanks in advance.
I'm trying to right a Multi-IM client (GAIM/ Trillian ) and am stumbling a little on the queueing system. Below is the code that I have right now (also attached). There is a listening thread, that then spawns a handler thread and goes back to listening. Im getting problems right now when 2 events come in at once, and event 2 before event 1, so I would create a queue, and in the listner just push that event on to the queue, but what how do i handle the executing of events ? Would it be another thread that sits in a forever while loop enumerating through the deque ? Any ideas are appreciated thanks!
void AIMMain() {
while (1) {
try {
uchar *data = new uchar[8192];
long rec = 0;
memset(data,0,8192);
if (g_aim->Main(data,rec)) {
ThreadData *d = new ThreadData(data,rec);
delete [] data;
CreateThread(0,0,(LPTHREAD_START_ROUTINE)AIMHandle,(LPVOID)d,0,0);
}
else break;
}
catch (...) {
AfxMessageBox("Fatal error");
break;
}
}
}
void AIMHandle(LPVOID d) {
AIMEvent event = g_aim->Handle(((ThreadData*)d)->data,((ThreadData*)d)->recvd);
switch (event.Type) {
case UIM_RECV_MESSAGE_ONLINE: {
AfxMessageBox(event.message.Message.c_str());
break;
}
case UIM_RECV_MESSAGE_OFFLINE: {
AfxMessageBox(event.message.Message.c_str());
break;
}
case UIM_BUDDY_WENT_ONLINE: {
theApp.m_pMainFrame->BuddyWentOnline(event.contact.ScreenName);
break;
}
case UIM_BUDDY_WENT_OFFLINE: {
// AfxMessageBox("OFFLINE");
// AfxMessageBox(event.contact.ScreenName.c_str());
break;
}
case UIM_LOGGED_IN: {
theApp.m_pMainFrame->StopAnimation();
theApp.m_pMainFrame->ResetAnimation();
theApp.m_pMainFrame->SetWindowText("Logged in");
AfxMessageBox("LOGGED IN");
break;
}
case UIM_ERROR:
if (event.ErrorCode == 0xa) {
}
break;
default :
break;
}
delete d;
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
- application/octet-stream attachment: StdAfx.cpp