各位大哥,小弟有个问题比较挠头,传递一个结构体,请教各位:
结构体;
struct MSG_C2S
{
string str_1MsgID;
string str_2Moid;
string str_3MsgIndex;
string str_4Ret;
string str_5Count;
list<string> list_6data;
};
客户端:
ACE_Message_Block *mb =
new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);
ACE_OutputCDR out( mb );
MSG_C2S msg1;
/*3*/
msg1.str_1MsgID = "00000001";
msg1.str_2Moid = "00000002";
msg1.str_3MsgIndex = "00000003";
msg1.str_4Ret = "00000004";
msg1.str_5Count = "00000003";
msg1.list_6data.push_back( "00000015");
msg1.list_6data.push_back( "00000016");
msg1.list_6data.push_back( "00000017");
out << ACE_CString( msg1.str_1MsgID.c_str() );
out << ACE_CString( msg1.str_2Moid.c_str() );
out << ACE_CString( msg1.str_3MsgIndex.c_str() );
out << ACE_CString( msg1.str_4Ret.c_str() );
out << ACE_CString( msg1.str_5Count.c_str() );
list<string>::iterator itor = msg1.list_6data.begin();
for ( ; itor != msg1.list_6data.end(); itor ++ )
{
out << ACE_CString( (*itor).c_str());
}
iovec iov1[1];
iov1[0].iov_base = out.begin()->rd_ptr();
iov1[0].iov_len = out.length();
return logging_peer_.sendv_n (iov1, 1);
服务器:
ACE_Message_Block *payload =new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE);
if ( m_LoggingPeer.recv_n( payload->wr_ptr(),65 ) == 65 )
{
payload->wr_ptr ( 65 );
// Create a CDR stream to parse the 8-byte header.
ACE_InputCDR cdr (payload);
ACE_CString str1,str2,str3,str4,str5;
cdr >> str1;
cdr>> str2;
cdr>> str3;
cdr>> str4;
cdr>> str5;
//以上数据均正常。。。
int ilength = 39;
payload->size( 65 + 39 + ACE_CDR::MAX_ALIGNMENT );
//ACE_CDR::grow(payload, 65 + 39 );
//ACE_CDR::grow (payload, 8 + ACE_CDR::MAX_ALIGNMENT + ilength);
list<string> listdata;
ACE_CString str6;
if( m_LoggingPeer.recv_n( payload->wr_ptr(), 39 ) == 39 )
{
payload->wr_ptr ( 39 );
for ( int i = 0; i< 3; i++ )
{
cdr>>str6;//此处无法接受到正常的数据是为啥。
string temp = str6.c_str();
listdata.push_back( temp );
}
}
/*
ACE_CDR::Char c;
ACE_CDR::UShort s;
cdr >> c;
cdr >> s;*/
}
问题1:str1~str5接受正常,为什么str6接受不正常?如果一次性接受65+39个字节就正常了,为什么分步骤接受不行呢?
问题2:能直接ACE_Message_Block 发送而不使用iovec 吗? |