本文整理汇总了C++中CBuffer::autorelease方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::autorelease方法的具体用法?C++ CBuffer::autorelease怎么用?C++ CBuffer::autorelease使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::autorelease方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runRead
bool CNetDelegate::runRead()
{
int nRet = m_oSocket.ccRead(m_pReadBuffer, SOCKET_READ_BUFFER_SIZE);
if( nRet == eSocketIoError || nRet == eSocketIoClosed )
{
unregisterScheduler();
m_oSocket.ccClose();
m_eStatus = eSocketIoClosed;
onDisconnected();
return true;
}
else
{
#if 1
CCLOG("CCSOCKET READ %d", nRet);
#endif
m_oReadBuffer.writeData(m_pReadBuffer, (unsigned int)nRet);
#if USING_PACKAGE_HEAD_LENGTH
while( m_oReadBuffer.isReadable(sizeof(int)) )
{
m_oReadBuffer.moveReaderIndexToFront();
int n_head_len = m_oReadBuffer.readInt();
if( n_head_len <= 0 )
{
CCLOGERROR("invalidate head length");
m_oReadBuffer.moveLeft(sizeof(int));
}
int n_content_len = (int)m_oReadBuffer.length();
if( n_content_len - (int)(sizeof(int)) >= n_head_len )
{
m_oReadBuffer.moveLeft(sizeof(unsigned int));
CBuffer* pData = m_oReadBuffer.readData(n_head_len);
m_oReadBuffer.moveLeft(n_head_len);
m_oReadBuffer.moveReaderIndexToFront();
m_oReadBuffer.moveWriterIndexToBack();
onMessageReceived(*pData);
#if USING_LUA
executeOnMessageReceivedScriptHandler(pData);
#endif
}else{
break;
}
}
#else
CBuffer* pData = (CBuffer*) m_oReadBuffer.copy();
pData->autorelease();
m_oReadBuffer.clear();
onMessageReceived(*pData);
#if USING_LUA
executeOnMessageReceivedScripHandler(pData);
#endif
#endif
}
return false;
}
示例2: send
void CNetDelegate::send(char* pBuffer, unsigned int uLen)
{
if( !pBuffer || uLen == 0 || !isConnected() )
return;
#if USING_PACKAGE_HEAD_LENGTH
CBuffer* pBuf = new CBuffer(pBuffer, uLen);
pBuf->autorelease();
send(pBuf);
#else
char* pTemp = new char[uLen];
memcpy(pTemp, pBuffer, uLen);
_SENDBUFFER tBuf;
tBuf.pBuffer = pTemp;
tBuf.nLength = (int)uLen;
tBuf.nOffset = 0;
m_lSendBuffers.push_back(tBuf);
#endif
}