本文整理汇总了C++中CBuffer::GetUsed方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::GetUsed方法的具体用法?C++ CBuffer::GetUsed怎么用?C++ CBuffer::GetUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::GetUsed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
CBuffer *CPackager::GetNextPack( BYTE cID )
{
CCriticalSection::Owner lock( m_csSend );
BUFFER_MAP::iterator it;
if ( m_theSend.end() != ( it = m_theSend.find( cID ) ) )
{
CBuffer *pBuffer = m_theSend[cID];
CBuffer *pPack = pBuffer->GetNextPack();
if ( NULL == pPack )
{
return NULL;
}
if ( 0 == pPack->GetUsed() )
{
pPack->Release();
return NULL;
}
CBuffer *pNewBufer = m_theAllocator.Allocate();
pNewBufer->AddData( cID );
BYTE cFlag = enumPackMiddle;
if ( !pBuffer->HaveNextPack() )
{
cFlag |= enumPackTail;
}
pNewBufer->AddData( cFlag );
/*
* Add a user data into this buffer
*/
unsigned long lnUserData = pBuffer->GetUserData();
pNewBufer->AddData( ( const char * )( &lnUserData ), sizeof( unsigned long ) );
/*
* Add some data into this buffer
*/
pNewBufer->AddData( pPack->GetBuffer(), pPack->GetUsed() );
pPack->Release();
return pNewBufer;
}
return NULL;
}
示例2: Send
bool CSmartClient::Send( const void * const pData, const size_t &datalength )
{
if (IsNormal())
{
if (m_pClient)
{
/*
* Send the histroy information to server
*/
{
CCriticalSection::Owner locker( m_csHistroyList );
stdList::iterator it;
for ( it = m_theHistroyList.begin();
it != m_theHistroyList.end();
it ++ )
{
CBuffer *pBuffer = *it;
if ( pBuffer )
{
m_pClient->SendPackToServer(
( const void * )( pBuffer->GetBuffer() ),
pBuffer->GetUsed() );
SAFE_RELEASE( pBuffer );
}
}
m_theHistroyList.clear();
}
if (pData && datalength)
m_pClient->SendPackToServer( pData, datalength );
return true;
}
}
else if (pData && datalength > 0)
{
/* Store data into buffer */
CCriticalSection::Owner locker( m_csHistroyList );
CBuffer *pBuffer = m_theAllocator.Allocate();
ASSERT( pBuffer );
pBuffer->AddData((BYTE*) pData, datalength );
m_theHistroyList.push_back( pBuffer );
}
return false;
}
示例3: _GetGameStat
void CClientNode::_GetGameStat( const void *pData, size_t dataLength )
{//发送游戏统计数据(By Fellow,2003.7.22)
ASSERT( m_pServer && pData && dataLength );
#ifdef CONSOLE_DEBUG
cout << "_GetGameStat::Begin" << endl;
#endif
//收到的数据包,只有控制字没有数据
TProcessData *pProData = ( TProcessData * )pData;
size_t nIdentity = pProData->ulIdentity;
//需要发送的数据包
CBuffer *pBuffer = m_theAllocator.Allocate();
TProcessData *pStatData =
reinterpret_cast< TProcessData * >( const_cast< BYTE * >( pBuffer->GetBuffer() ) );
int nDataLen = sizeof(TGAME_STAT_DATA);
pStatData->nProtoId = s2c_gamestatistic;
pStatData->ulIdentity = nIdentity;
pStatData->nDataLen = nDataLen;
//取得统计数据
TGAME_STAT_DATA* myGameStatData = (TGAME_STAT_DATA*)pStatData->pDataBuffer;
GetGameStat(myGameStatData);
int nUsedLen = sizeof( TProcessData ) - 1 + nDataLen;
pBuffer->Use( nUsedLen );
//发送
m_theSend.AddData( s2c_gamestatistic_bigpackage, pBuffer->GetBuffer(), nUsedLen );
CBuffer *pPack = m_theSend.GetHeadPack( s2c_gamestatistic_bigpackage );
while ( pPack )
{
m_pServer->SendData( m_nIndentity, ( const void * )pPack->GetBuffer(), pPack->GetUsed() );
SAFE_RELEASE( pPack );
pPack = m_theSend.GetNextPack( s2c_gamestatistic_bigpackage );
}
m_theSend.DelData( s2c_gamestatistic_bigpackage );
SAFE_RELEASE( pPack );
SAFE_RELEASE( pBuffer );
#ifdef CONSOLE_DEBUG
cout << "_GetGameStat::End" << endl;
#endif
}
示例4: LargePackProcess
void CClientNode::LargePackProcess( const void *pData, size_t dataLength )
{
ASSERT( pData && dataLength );
CBuffer *pBuffer = m_theRecv.PackUp( pData, dataLength );
if ( pBuffer )
{
m_theDataQueue.AddData( pBuffer->GetBuffer(), pBuffer->GetUsed() );
SAFE_RELEASE( pBuffer );
}
}
示例5: Process
void CClientNode::Process()
{
CBuffer *pBuffer = m_theDataQueue.Get();
if ( pBuffer )
{
const BYTE *pData = pBuffer->GetBuffer();
const size_t dataLength = pBuffer->GetUsed();
BYTE cProtocol = CPackager::Peek( pData );
if ( cProtocol < c2s_end && m_theProcessArray[cProtocol] )
{
( this->*m_theProcessArray[cProtocol] )( ( const void * )pData, dataLength );
}
}
SAFE_RELEASE( pBuffer );
}
示例6: _GetRoleInfo
void CClientNode::_GetRoleInfo( const void *pData, size_t dataLength )
{
ASSERT( m_pServer && pData && dataLength );
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::Begin" << endl;
#endif
TProcessData *pRoleInfo = ( TProcessData * )pData;
char szRoleName[_NAME_LENGTH];
int nDataLen = pRoleInfo->nDataLen;
nDataLen = ( nDataLen > _NAME_LENGTH ) ? _NAME_LENGTH : nDataLen;
CBuffer *pBuffer = m_theAllocator.Allocate();
TProcessData *pRoleData = reinterpret_cast< TProcessData * >( const_cast< BYTE * >( pBuffer->GetBuffer() ) );
int nUsedLength = sizeof( TProcessData );
size_t nIdentity = pRoleInfo->ulIdentity;
pRoleData->nProtoId = s2c_roleserver_getroleinfo_result;
pRoleData->pDataBuffer[0] = -1;
pRoleData->nDataLen = 1;
pRoleData->ulIdentity = nIdentity;
if ( nDataLen > 0 )
{
memcpy( szRoleName, &pRoleInfo->pDataBuffer[0], nDataLen );
szRoleName[nDataLen] = '\0';
int result = -1;
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::GetRoleInfo " << szRoleName << endl;
#endif
int nRoleInfoLen = 0;
if (!IsRoleLock(szRoleName))
GetRoleInfo( &pRoleData->pDataBuffer[1], szRoleName, nRoleInfoLen );
if ( nRoleInfoLen > 0 )
{
pRoleData->pDataBuffer[0] = 1;
pRoleData->nDataLen = nRoleInfoLen + 1;
nUsedLength = sizeof( TProcessData ) + nRoleInfoLen;
}
}
pBuffer->Use( nUsedLength );
m_theSend.AddData( s2c_roleserver_getroleinfo_result, pBuffer->GetBuffer(), nUsedLength, nIdentity );
CBuffer *pPack = m_theSend.GetHeadPack( s2c_roleserver_getroleinfo_result );
while ( pPack )
{
m_pServer->SendData( m_nIndentity, ( const void * )pPack->GetBuffer(), pPack->GetUsed() );
SAFE_RELEASE( pPack );
pPack = m_theSend.GetNextPack( s2c_roleserver_getroleinfo_result );
}
m_theSend.DelData( s2c_roleserver_getroleinfo_result );
SAFE_RELEASE( pPack );
SAFE_RELEASE( pBuffer );
#ifdef CONSOLE_DEBUG
cout << "_GetRoleInfo::End" << endl;
#endif
}