高手赐教: 基于ACE的服务器为何不能连续收包
我在SUSE Linux 10.0/g++ 4.03下编译安装ACE 5.5 运行自带的Proactor测试程序exsample/Reactor/Proactor/test_proactor2.cppy一切正常:在两个进程分别启动测试程序作为服务器和客户端,服务器可以正常收包、回写,然后继续收包,起大致流程是:read stream -> handle read -> write back -> handle write -> read stream ... (循环)
我将handle_read_stream()函数中的回发部分的代码注释掉,想是服务器不讲收到的包发回服务器而继续接受来自客户端的信息,代码如下
void Receiver::handle_read_stream (...)
{
...
if ( result.success () && result.bytes_transferred () != 0)
{
//////////////////////////////////////////////////////////////////
// if(this->initiate_write_stream (result.message_block (),
// sult.bytes_transferred () ) == 0 )
//////////////////////////////////////////////////////////////////
{
if ( duplex != 0 )
{
// Initiate new read from the stream.
this->initiate_read_stream () ;
}
}
}
else
...
}
但服务器在收到第一个包后(程序在打开端口后首先执行一次ACE_Asynch_Read_Stream的读操作),不能继续收包,在其他ACE论坛上看到大部分Linux对异步IO支持的不好(测试程序使用的是ACE_POSIX_SIG_Proactor),但鉴于修改前的原始测试程序仍然可以正常运行,是否可以排除SUSE Linux对异步IO支持不好的因素,那么问题出在哪里呢,如何不进行交替读写,使服务器连续收包?
注:上述修改后的测试代码可以在Windows下(ACE_WIN32_Proactor)测试通过,连续收包。