|
楼主 |
发表于 2008-9-9 19:08:27
|
显示全部楼层
这个参数我用过.
在发起异步读的时候,传进去,用来标识一下这个写操作是"干什么"的,然后在"handle_read_stream()"根据act来选择不同的行为.
下面是代码片段
enum MessageTypes_T
{
MT_INVAILD = -1,
MT_HEADER_FLAG = 10,
MT_SIZE,
MT_PAYLOAD_BODY,
MT_SIZE_2,
MT_TAIL_FLAG
};
发起异步读操作的时候
int result = this->read(header,(void*) MT_HEADER_FLAG);
处理"读操作完成"时
const void* act = result.act();
intptr_t mode = (intptr_t) (act);
switch(mode)
{
case MT_HEADER_FLAG :
do
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("read header flag\n")));
returnCode = this->completeMsgHeaderFlag(mb);
if (returnCode == 0)
{
ACE_Message_Block *mb;
ACE_NEW_NORETURN(mb,
ACE_Message_Block(2 * sizeof (ACE_UINT16),
ACE_Message_Block::MB_DATA));
int result = this->read(mb,(void*)MT_SIZE);
}
else
{
this->readError(MT_HEADER_FLAG);
}
} while (0);
break;
case MT_SIZE:
do
{
ACE_DEBUG((LM_DEBUG,ACE_TEXT("read pack size complete\n")));
returnCode = this->completeMsgSize(mb);
if (returnCode == 0)
{
ACE_Message_Block *mb;
ACE_NEW_NORETURN(mb,
ACE_Message_Block(this->payloadSize_ ,
ACE_Message_Block::MB_DATA));
this->read(mb,(void*)MT_PAYLOAD_BODY) ;
}
else
{
this->readError(MT_SIZE);
}
}while (0);
break;
case MT_PAYLOAD_BODY:
..... |
|