|
1.main.cpp
#include "Header.h"
class HA_CommandHandler:public ACE_Task<ACE_MT_SYNCH>
{
public:
HA_CommandHandler(const char * name) : name_(name){
}
virtual int svc(void)
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("%t starting up %C %D\n"),name_));
ACE_OS::sleep(3);
ACE_Message_Block *mb = 0;
while (this->getq(mb) > 0){
process_message();
}
return 0;
}
void process_message()
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%t) processing message %C %D\n"),name_));
}
private:
const char * name_;
};
int ACE_TMAIN(int, ACE_TCHAR *[])
{
HA_CommandHandler lp_handler("low");
lp_handler.activate();
ACE_DEBUG((LM_DEBUG,ACE_TEXT("start hp_handler succeed. %D\n")));
ACE_Message_Block mb;
for (int i = 0 ; i < 10 ; i ++)
{
lp_handler.putq(&mb);
}
ACE_DEBUG((LM_DEBUG,ACE_TEXT("putq succeed. %D\n")));
lp_handler.wait();
return 0;
}
2. Header.h
#ifndef HEADER_H
#define HEADER_H
/// ace include
#include <ace/ACE.h>
#include <ace/OS.h>
#include <ace/Log_Msg.h>
#include <ace/SOCK_Dgram.h>
#include <ace/Reactor.h>
#include <ace/Svc_Handler.h>
#include <ace/Synch.h>
#include <ace/SOCK_Acceptor.h>
#include <ace/SOCK_Connector.h>
#include <ace/Signal.h>
#include <ace/Version.h>
#include <ace/Synch.h>
#include <ace/Event.h>
#include <ace/Acceptor.h>
#include <ace/Connector.h>
#include <ace/Process.h>
#include <ace/High_Res_Timer.h>
#include <ace/FILE_IO.h>
#include <ace/FILE_Addr.h>
#include <ace/FILE_Connector.h>
#include <ace/DEV_IO.h>
#include <ace/DEV_Addr.h>
#include <ace/DEV_Connector.h>
#include <ace/TTY_IO.h>
#include <ace/Time_Value.h>
#include <ace/Timer_Heap_T.h>
#include <ace/Timer_Queue_Adapters.h>
#include <ace/SOCK_Dgram_Bcast.h>
#include <ace/SOCK_Dgram_Mcast.h>
#include "ace/System_Time.h"
#include "ace/os_include/os_pthread.h"
/// stl include
#include <exception>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <iostream>
#endif // HEADER_H
哪位大侠帮看看,为什么不论我扔进去多少条消息,最多只能取出两条呢,然后getq就不返回了,一直阻塞在那里。 |
|