|
发表于 2009-6-3 11:38:27
|
显示全部楼层
skillzero,您好!我按照你的思路去修改程序测试后发现并没有你说的10M+的效果,帮忙看下我的程序。代码如下:
int
Receiver::initiate_read_stream (void)
{
ACE_Message_Block *mb = 0;
ACE_NEW_RETURN (mb,
ACE_Message_Block (65535+ 1),
-1);
if (this->rs_.read (*mb,
mb->size () - 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"ACE_Asynch_Read_Stream::read"),
-1);
return 0;
}
void
Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
{
ACE_DEBUG ((LM_DEBUG,
"handle_read_stream called\n"));
size_t actualBytes=result.bytes_transferred();
result.message_block ().rd_ptr ()[ result.bytes_transferred ()] = '\0';
ACE_DEBUG ((LM_DEBUG, "********************\n"));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "act", (u_long) result.act ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "completion_key", (u_long) result.completion_key ()));
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
#if 0
// This can overrun the ACE_Log_Msg buffer and do bad things.
// Re-enable it at your risk.
ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ()));
#endif /* 0 */
if (result.success () && result.bytes_transferred () != 0)
{
if (this->wf_.write (result.message_block (),
result.bytes_transferred (),
this->file_offset_) == -1)
{
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE_Asynch_Write_File::write"));
return;
}
if(actualBytes<needDataLength_) //needDataLength_声明为全局变量为65535
{
ACE_DEBUG ((LM_DEBUG,"readed bytes(%d) is less than needed bytes(%d)\n",actualBytes,needDataLength_));
size_t dataLength = needDataLength_-actualBytes;
ACE_Message_Block* pMessageBlock;
ACE_NEW_NORETURN(pMessageBlock,ACE_Message_Block(dataLength+1));
if(this->rs_.read(*pMessageBlock,pMessageBlock->space()-1)!=0)
{
pMessageBlock->release();
// needDataLength_=dataLength;
}
needDataLength_=dataLength;
return;
}
needDataLength_=65535;
// Initiate new read from the stream.
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Receiver completed\n"));
result.message_block ().release ();
delete this;
}
if (this->initiate_read_stream () == -1)
return;
} |
|