本文整理汇总了C++中CBuffer::SetUserData方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::SetUserData方法的具体用法?C++ CBuffer::SetUserData怎么用?C++ CBuffer::SetUserData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::SetUserData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddData
void CPackager::AddData( BYTE cID, const char * const pData, size_t dataLength, unsigned long lnUserData /* = 0 */ )
{
CCriticalSection::Owner lock( m_csSend );
BUFFER_MAP::iterator it;
if ( m_theSend.end() != ( it = m_theSend.find( cID ) ) )
{
CBuffer *pBuffer = m_theSend[cID];
ASSERT( pBuffer );
pBuffer->SetUserData( lnUserData );
pBuffer->AddData( pData, dataLength );
}
else
{
CBuffer *pBuffer = m_theAllocator.Allocate();
ASSERT( pBuffer );
pBuffer->SetUserData( lnUserData );
pBuffer->AddData( pData, dataLength );
m_theSend[cID] = pBuffer;
}
}
示例2: lock
CBuffer *CPackager::PackUp( const void *pData, size_t dataLength )
{
CCriticalSection::Owner lock( m_csRecv );
if ( NULL == pData || dataLength < 3 /* cID + cPackFlag + ... */ )
{
return NULL;
}
BYTE cID = CPackager::Peek( pData );
BUFFER_MAP::iterator it;
if ( m_theRecv.end() == ( it = m_theRecv.find( cID ) ) )
{
CBuffer *pPack = m_theAllocator.Allocate();
m_theRecv[cID] = pPack;
}
CBuffer *pBuffer = m_theRecv[cID];
ASSERT( pBuffer );
BYTE cFlag = CPackager::Peek( pData, 1 );
const size_t nDataBegin = 1 + 1 + sizeof( unsigned long );
if ( _Header( cFlag ) )
{
pBuffer->Empty();
pBuffer->AddData( ( ( const char * )pData + nDataBegin ), dataLength - nDataBegin );
}
if ( _Middle( cFlag ) )
{
pBuffer->AddData( ( ( const char * )pData + nDataBegin ), dataLength - nDataBegin );
}
if ( _Tail( cFlag ) )
{
unsigned long lnUserData = *( const unsigned long * )( ( const char * )pData + 2 );
pBuffer->SetUserData( lnUserData );
pBuffer->AddRef();
return pBuffer;
}
if ( _Error( cFlag ) )
{
ASSERT( NULL && "CPackager::PackUp - Invalid package!" );
}
return NULL;
}