本文整理汇总了C++中ACE_OutputCDR::end方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_OutputCDR::end方法的具体用法?C++ ACE_OutputCDR::end怎么用?C++ ACE_OutputCDR::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_OutputCDR
的用法示例。
在下文中一共展示了ACE_OutputCDR::end方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
int DataWrapper::write(const ACE_OutputCDR& cdr)
{
//This method writes to an ace socket stream. First, it will collect
//the appropriate header which includes the message length. It will then
//combine ACE blocks that hold the header and message, and send it.
//If preparing the block or sending fails, it returns an appropriate error.
//If the actual socket send fails, the connection will be closed (not sure what
//else to do, since it shouldn't fail under a good connection)
if(!cdr.good_bit())
ACE_ERROR_RETURN((LM_ERROR, "%s, %p\n",toString(theAddress).c_str(),"Failed while sending CDR"), -1);
ACE_OutputCDR aceHead(headerLength);
//Put header info into a CDR
if(!(aceHead << (ACE_CDR::ULong)bitsForward) || !(aceHead << (ACE_CDR::ULong)cdr.length()))
ACE_ERROR_RETURN( (LM_ERROR, "%s, %p\n",toString(theAddress).c_str(),"Failed while sending, CDR header"), -1 );
//Create a block with the header and message
const_cast<ACE_Message_Block*>(aceHead.begin())->cont(const_cast<ACE_Message_Block*>(cdr.begin()));
const ssize_t msgLength = headerLength + ACE_CDR::total_length(cdr.begin(), cdr.end());
// cout << toString(theAddress) << endl;
//Send the message
const ssize_t bytesSent = theStream.send_n(aceHead.begin());
// Clear the block
const_cast<ACE_Message_Block*>(aceHead.begin())->cont(NULL);
//Check whether the send succeeded (sent all the bytes). If not, we assume the socket has disconnected.
// cout << "Bytes sent: " << bytesSent << " | msgLength: " << msgLength << endl;
if( bytesSent != msgLength ) {
theStream.close_writer();
ACE_ERROR_RETURN((LM_ERROR, "%s - %p\n",toString(theAddress).c_str(),"Socket failed while sending"), -1);
}
//Everything sent successfully
return 0;
}