void TN_Pro_Service::handle_read_stream( const ACE_Asynch_Read_Stream::Result &result )
{
LogInfo("handle_read_stream");
ACE_Message_Block &mb = result.message_block();
if (!result.success() || result.bytes_transferred() == 0)
{
mb.release();
delete this;
}else
{
char temp[100];
LogInfo("receive message[%s]",mb.rd_ptr());
mb.release();
if (strcmp(temp,"tian") == 0)
{
ACE_Message_Block * mb1;
ACE_NEW_NORETURN(mb1,ACE_Message_Block(1024));
sprintf(mb1->wr_ptr(),"Hello Tian");
mb1->wr_ptr(20);
this->writer_.write(*mb1,1024);
}
cycle_read();
}
}
void TN_Pro_Service::handle_write_stream( const ACE_Asynch_Write_Stream::Result &result )
{
LogInfo("handle_write_stream");
ACE_Message_Block &mb = result.message_block();
if (!result.success() || result.bytes_transferred() == 0)
{
mb.release();
delete this;
}else
{
mb.release();
}
}
void TN_Pro_Service::open( ACE_HANDLE h,ACE_Message_Block &mb )
{
this->handle(h);
if (this->reader_.open(*this) != 0 || this->writer_.open(*this) !=0)
{
delete this;
return;
}
cycle_read();
}
int TN_Pro_Service::cycle_read()
{
ACE_Message_Block *mb;
ACE_NEW_NORETURN(mb,ACE_Message_Block(2048));
if ( this->reader_.read(*mb,2048) != 0)
{
mb->release();
delete this;
return 1;
}
return 1;
}
问题出在cycle_read()的if ( this->reader_.read(*mb,2048) != 0)这一句上,接收超过168个字节就会出现问题,而低于168个字节则正常。 |