本文整理汇总了C++中PacketBuffer::Pop方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketBuffer::Pop方法的具体用法?C++ PacketBuffer::Pop怎么用?C++ PacketBuffer::Pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketBuffer
的用法示例。
在下文中一共展示了PacketBuffer::Pop方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NetClientThread
int NetClientThread( void *client )
{
NetClient *net_client = (NetClient *) client;
char data[ PACKET_BUFFER_SIZE ] = "";
PacketBuffer Buffer;
while( net_client->Connected )
{
// Check for packets.
int size = 0;
if( ( size = SDLNet_TCP_Recv( net_client->Socket, data, PACKET_BUFFER_SIZE ) ) > 0 )
{
if( ! net_client->Connected )
break;
net_client->BytesReceived += size;
Buffer.AddData( data, size );
while( Packet *packet = Buffer.Pop() )
{
SDL_mutexP( net_client->Lock );
net_client->InBuffer.push( packet );
SDL_mutexV( net_client->Lock );
}
}
else
{
// If 0 (disconnect) or -1 (error), stop listening.
if( size < 0 )
net_client->DisconnectMessage = std::string("SDLNet_TCP_Recv: ") + std::string(SDLNet_GetError());
net_client->Disconnect();
break;
}
// Let the thread rest a bit.
SDL_Delay( 1 );
}
// Set the thread pointer to NULL when we disconnect.
net_client->Thread = NULL;
return 0;
}