|
//头文件-
- #include "ace/Task.h"
- #include "ace/Synch.h"
- #include "ace/Message_Block.h"
- #include "ace/Log_Msg.h"
- #include "ace/Stream.h"
- class S_Task_1 : public ACE_Task<ACE_MT_SYNCH>
- {
- int open(void* = 0){return this->activate();}
- int svc(void)
- {
- ACE_Message_Block *mb;
- for (mb = 0; ; )
- {
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("S_Task::svc() - ") ACE_TEXT ("waiting for work\n" )));
- this->getq (mb);
-
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("S_Task_1 run \n")));
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("Data %s\n"), mb->rd_ptr()));
- this->put_next(mb);
- }
- }
- };
- class S_Task_2 : public ACE_Task<ACE_MT_SYNCH>
- {
- int open(void* = 0){return this->activate();}
- int svc(void)
- {
- ACE_Message_Block *mb;
- for (mb = 0; ; )
- {
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("S_Task::svc() - ") ACE_TEXT ("waiting for work\n" )));
- this->getq (mb);
-
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("S_Task_2 run \n")));
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("Data %s\n"), mb->rd_ptr()));
- this->put_next(mb);
- }
- }
- };
- class End_Task : public ACE_Task<ACE_MT_SYNCH>
- {
- int open(void* = 0){return this->activate();}
- int svc(void)
- {
- ACE_Message_Block *mb;
- for (mb = 0; ; )
- {
- ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("S_Task::svc() - ") ACE_TEXT ("waiting for work\n" )));
- this->getq (mb);
-
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("End_Task run \n")));
- ACE_DEBUG((LM_DEBUG, ACE_TEXT ("Data %s\n"), mb->rd_ptr()));
- mb->release();
- }
- }
- };
- class S_Stream : public ACE_Stream<ACE_MT_SYNCH>
- {
- public:
- typedef ACE_Stream<ACE_MT_SYNCH> inherited;
- typedef ACE_Module<ACE_MT_SYNCH> Module;
- S_Stream():inherited(){};
- int open (void)
- {
- ACE_DEBUG((LM_DEBUG, ACE_TEXT("Stream open!\n")));
- Module* endModule;
- End_Task * end_ = new End_Task();
- ACE_NEW_RETURN(endModule,
- Module("End Module", end_),
- -1);
- this->inherited::open((void*)0, (Module*)0, endModule);
- Module* module1;
- ACE_NEW_RETURN(module1,
- Module("module1", new S_Task_1()),
- -1);
- Module* module2;
- ACE_NEW_RETURN(module2,
- Module("module2", new S_Task_2()),
- -1);
- this->push(module1);
- this->push(module2);
- return 0;
- }
- };
- //实现文件
- #include "SimpleStream.h"
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- int ACE_TMAIN (int, ACE_TCHAR *[])
- {
- ACE_Message_Block *input = new ACE_Message_Block();
- char *testData = "Test Data Body!";
- input->copy(testData, strlen(testData));
- S_Stream s;
- s.open();
- s.put(input);
- ACE_Message_Block *output;
- s.get(output);
- cout<< "Message Body:" << *output->rd_ptr();
- system("PAUSE");
- return 0;
- }
复制代码 编译完了以后几个Module都阻塞在get方法上了,我在主函数里put数据了啊,为什么所有的Module都get()不到数据呢??
谁来给解决一下啊,我初学Stream框架,谢谢了!! |
|