|
- void Receiver::handle_read_stream(const ACE_Asynch_Read_Stream::Result &result)
- {
- if (!result.success()||result.bytes_transferred()==0)
- {
- cout<<"delete ..."<<endl;
- delete this;
- return ;
- }
- //ProactorTPSingleton::instance()->putq(&result.message_block());
- //ACE_OS::printf("%d:putq\n",global++);
- else if (mblk_->length() == SIZE_TO_READ)//获得需要接收的字节数
- {
- cout<<"sizetoread == "<<SIZE_TO_READ<<endl;
- cout<<"data is..."<<mblk_->rd_ptr()<<endl;
- cout<<"trasfered "<<result.bytes_transferred()<<endl;
- /* ACE_InputCDR cdr (mblk_); 参照C++NP2上的例子没得到正确结果
- ACE_CDR::Boolean byte_order;
- cdr >> ACE_InputCDR::to_boolean (byte_order);
- cdr.reset_byte_order (byte_order);
- ACE_CDR::ULong length;
- cdr >> length;
- cout<<"need read :"<<length<<endl;*/
- char *len = mblk_->rd_ptr();
- u_long length = atoi(len);
- cout<<"need read :"<<length<<endl;
- mblk_->size(length+SIZE_TO_READ);//扩大容量,接收数据
- rs_.read(*mblk_,length);//投递读
- }
- else//问题出在这,执行上面的else if时,这个else语句块也执行!!!不解
- {
- cout<<"recv data..."<<mblk_->rd_ptr()<< endl;
- ProactorTPSingleton::instance()->putq(mblk_);
- ACE_NEW(mblk_,ACE_Message_Block(SIZE_TO_READ));
- //ACE_CDR::mb_align (mblk_);
- rs_.read(*mblk_,SIZE_TO_READ);
- cout<<" another read ..."<<endl;
- }
- };
复制代码 |
|