本文整理汇总了C++中datastructures::Queue::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::IsEmpty方法的具体用法?C++ Queue::IsEmpty怎么用?C++ Queue::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datastructures::Queue
的用法示例。
在下文中一共展示了Queue::IsEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateThreaded
void UDPForwarder::UpdateThreaded(void)
{
fd_set readFD;
//fd_set exceptionFD;
FD_ZERO(&readFD);
// FD_ZERO(&exceptionFD);
timeval tv;
int selectResult;
tv.tv_sec=0;
tv.tv_usec=0;
RakNet::TimeMS curTime = RakNet::GetTimeMS();
SOCKET largestDescriptor=0;
DataStructures::DefaultIndexType i;
// Remove unused entries
i=0;
while (i < forwardList.GetSize())
{
if (curTime > forwardList[i]->timeLastDatagramForwarded && // Account for timestamp wrap
curTime > forwardList[i]->timeLastDatagramForwarded+forwardList[i]->timeoutOnNoDataMS)
{
RakNet::OP_DELETE(forwardList[i],_FILE_AND_LINE_);
forwardList.RemoveAtIndex(i,_FILE_AND_LINE_);
}
else
i++;
}
if (forwardList.GetSize()==0)
return;
for (i=0; i < forwardList.GetSize(); i++)
{
#ifdef _MSC_VER
#pragma warning( disable : 4127 ) // warning C4127: conditional expression is constant
#endif
FD_SET(forwardList[i]->readSocket, &readFD);
// FD_SET(forwardList[i]->readSocket, &exceptionFD);
if (forwardList[i]->readSocket > largestDescriptor)
largestDescriptor = forwardList[i]->readSocket;
}
#if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
#else
selectResult=(int) select((int) largestDescriptor+1, &readFD, 0, 0, &tv);
#endif
char data[ MAXIMUM_MTU_SIZE ];
sockaddr_in sa;
socklen_t len2;
if (selectResult > 0)
{
DataStructures::Queue<ForwardEntry*> entriesToRead;
ForwardEntry *feSource;
for (i=0; i < forwardList.GetSize(); i++)
{
feSource = forwardList[i];
// I do this because I'm updating the forwardList, and don't want to lose FD_ISSET as the list is no longer in order
if (FD_ISSET(feSource->readSocket, &readFD))
entriesToRead.Push(feSource,__FILE__,__LINE__);
}
while (entriesToRead.IsEmpty()==false)
{
feSource=entriesToRead.Pop();
const int flag=0;
int receivedDataLen, len=0;
unsigned short portnum=0;
len2 = sizeof( sa );
sa.sin_family = AF_INET;
receivedDataLen = recvfrom( feSource->readSocket, data, MAXIMUM_MTU_SIZE, flag, ( sockaddr* ) & sa, ( socklen_t* ) & len2 );
portnum = ntohs( sa.sin_port );
if (feSource->srcAndDest.source.binaryAddress==sa.sin_addr.s_addr)
{
if (feSource->updatedSourceAddress==false)
{
feSource->updatedSourceAddress=true;
if (feSource->srcAndDest.source.port!=portnum)
{
// Remove both source and dest from list, update addresses, and reinsert in order
DataStructures::DefaultIndexType sourceIndex, destIndex;
SrcAndDest srcAndDest;
srcAndDest.source=feSource->srcAndDest.destination;
srcAndDest.destination=feSource->srcAndDest.source;
destIndex=forwardList.GetIndexOf(srcAndDest);
ForwardEntry *feDest = forwardList[destIndex];
forwardList.RemoveAtIndex(destIndex,__FILE__,__LINE__);
srcAndDest.source=feSource->srcAndDest.source;
srcAndDest.destination=feSource->srcAndDest.destination;
sourceIndex=forwardList.GetIndexOf(srcAndDest);
//.........这里部分代码省略.........
示例2: Send
void FileListTransfer::Send(FileList *fileList, RakPeerInterface *rakPeer, SystemAddress recipient, unsigned short setID, PacketPriority priority, char orderingChannel, bool compressData, IncrementalReadInterface *_incrementalReadInterface, unsigned int _chunkSize)
{
(void) compressData;
if (callback)
fileList->SetCallback(callback);
unsigned int i, totalLength;
RakNet::BitStream outBitstream;
bool sendReference;
const char *dataBlocks[2];
int lengths[2];
totalLength=0;
for (i=0; i < fileList->fileList.Size(); i++)
{
const FileListNode &fileListNode = fileList->fileList[i];
totalLength+=fileListNode.fileLengthBytes;
}
// Write the chunk header, which contains the frequency table, the total number of files, and the total number of bytes
bool anythingToWrite;
outBitstream.Write((MessageID)ID_FILE_LIST_TRANSFER_HEADER);
outBitstream.Write(setID);
anythingToWrite=fileList->fileList.Size()>0;
outBitstream.Write(anythingToWrite);
if (anythingToWrite)
{
outBitstream.WriteCompressed(fileList->fileList.Size());
outBitstream.WriteCompressed(totalLength);
if (rakPeer)
rakPeer->Send(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
else
SendUnified(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
DataStructures::Queue<FileToPush*> filesToPush;
for (i=0; i < fileList->fileList.Size(); i++)
{
sendReference = fileList->fileList[i].isAReference && _incrementalReadInterface!=0;
if (sendReference)
{
FileToPush *fileToPush = RakNet::OP_NEW<FileToPush>(__FILE__,__LINE__);
fileToPush->fileListNode.context=fileList->fileList[i].context;
fileToPush->setIndex=i;
fileToPush->fileListNode.filename=fileList->fileList[i].filename;
fileToPush->fileListNode.fullPathToFile=fileList->fileList[i].fullPathToFile;
fileToPush->fileListNode.fileLengthBytes=fileList->fileList[i].fileLengthBytes;
fileToPush->fileListNode.dataLengthBytes=fileList->fileList[i].dataLengthBytes;
// fileToPush->systemAddress=recipient;
fileToPush->setID=setID;
fileToPush->packetPriority=priority;
fileToPush->orderingChannel=orderingChannel;
fileToPush->currentOffset=0;
fileToPush->incrementalReadInterface=_incrementalReadInterface;
fileToPush->chunkSize=_chunkSize;
filesToPush.Push(fileToPush,__FILE__,__LINE__);
}
else
{
outBitstream.Reset();
outBitstream.Write((MessageID)ID_FILE_LIST_TRANSFER_FILE);
outBitstream.Write(fileList->fileList[i].context);
outBitstream.Write(setID);
stringCompressor->EncodeString(fileList->fileList[i].filename, 512, &outBitstream);
outBitstream.WriteCompressed(i);
outBitstream.WriteCompressed(fileList->fileList[i].dataLengthBytes); // Original length in bytes
outBitstream.AlignWriteToByteBoundary();
dataBlocks[0]=(char*) outBitstream.GetData();
lengths[0]=outBitstream.GetNumberOfBytesUsed();
dataBlocks[1]=fileList->fileList[i].data;
lengths[1]=fileList->fileList[i].dataLengthBytes;
SendListUnified(dataBlocks,lengths,2,priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
}
}
if (filesToPush.IsEmpty()==false)
{
FileToPushRecipient *ftpr=0;
filesToPushAllSameAddressMutex.Lock();
for (unsigned int i=0; i < filesToPushAllSameAddress.Size(); i++)
{
if (filesToPushAllSameAddress[i]->systemAddress==recipient)
{
ftpr=filesToPushAllSameAddress[i];
break;
}
}
if (ftpr==0)
{
ftpr = RakNet::OP_NEW<FileToPushRecipient>(__FILE__,__LINE__);
ftpr->systemAddress=recipient;
filesToPushAllSameAddress.Push(ftpr, __FILE__,__LINE__);
}
while (filesToPush.IsEmpty()==false)
{
//.........这里部分代码省略.........
示例3: UpdateThreaded_Old
void UDPForwarder::UpdateThreaded_Old(void)
{
fd_set readFD;
//fd_set exceptionFD;
FD_ZERO(&readFD);
// FD_ZERO(&exceptionFD);
timeval tv;
int selectResult;
tv.tv_sec=0;
tv.tv_usec=0;
RakNet::TimeMS curTime = RakNet::GetTimeMS();
SOCKET largestDescriptor=0;
DataStructures::DefaultIndexType i;
// Remove unused entries
i=0;
while (i < forwardList.GetSize())
{
if (curTime > forwardList[i]->timeLastDatagramForwarded && // Account for timestamp wrap
curTime > forwardList[i]->timeLastDatagramForwarded+forwardList[i]->timeoutOnNoDataMS)
{
RakNet::OP_DELETE(forwardList[i],_FILE_AND_LINE_);
forwardList.RemoveAtIndex(i,_FILE_AND_LINE_);
}
else
i++;
}
if (forwardList.GetSize()==0)
return;
for (i=0; i < forwardList.GetSize(); i++)
{
#ifdef _MSC_VER
#pragma warning( disable : 4127 ) // warning C4127: conditional expression is constant
#endif
FD_SET(forwardList[i]->socket, &readFD);
// FD_SET(forwardList[i]->readSocket, &exceptionFD);
if (forwardList[i]->socket > largestDescriptor)
largestDescriptor = forwardList[i]->socket;
}
#if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
#else
selectResult=(int) select((int) largestDescriptor+1, &readFD, 0, 0, &tv);
#endif
char data[ MAXIMUM_MTU_SIZE ];
sockaddr_in sa;
socklen_t len2;
if (selectResult > 0)
{
DataStructures::Queue<ForwardEntry*> entriesToRead;
ForwardEntry *forwardEntry;
for (i=0; i < forwardList.GetSize(); i++)
{
forwardEntry = forwardList[i];
// I do this because I'm updating the forwardList, and don't want to lose FD_ISSET as the list is no longer in order
if (FD_ISSET(forwardEntry->socket, &readFD))
entriesToRead.Push(forwardEntry,_FILE_AND_LINE_);
}
while (entriesToRead.IsEmpty()==false)
{
forwardEntry=entriesToRead.Pop();
const int flag=0;
int receivedDataLen, len=0;
unsigned short portnum=0;
len2 = sizeof( sa );
sa.sin_family = AF_INET;
receivedDataLen = recvfrom( forwardEntry->socket, data, MAXIMUM_MTU_SIZE, flag, ( sockaddr* ) & sa, ( socklen_t* ) & len2 );
if (receivedDataLen<0)
{
#if defined(_WIN32) && defined(_DEBUG) && !defined(_XBOX) && !defined(X360)
DWORD dwIOError = WSAGetLastError();
if (dwIOError!=WSAECONNRESET && dwIOError!=WSAEINTR && dwIOError!=WSAETIMEDOUT)
{
LPVOID messageBuffer;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, dwIOError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
( LPTSTR ) & messageBuffer, 0, NULL );
// something has gone wrong here...
RAKNET_DEBUG_PRINTF( "recvfrom failed:Error code - %d\n%s", dwIOError, messageBuffer );
//Free the buffer.
LocalFree( messageBuffer );
}
#endif
continue;
}
//.........这里部分代码省略.........
示例4: Send
void FileListTransfer::Send(FileList *fileList, SLNet::RakPeerInterface *rakPeer, SystemAddress recipient, unsigned short setID, PacketPriority priority, char orderingChannel, IncrementalReadInterface *_incrementalReadInterface, unsigned int _chunkSize)
{
for (unsigned int flpcIndex=0; flpcIndex < fileListProgressCallbacks.Size(); flpcIndex++)
fileList->AddCallback(fileListProgressCallbacks[flpcIndex]);
unsigned int i, totalLength;
SLNet::BitStream outBitstream;
bool sendReference;
const char *dataBlocks[2];
int lengths[2];
totalLength=0;
for (i=0; i < fileList->fileList.Size(); i++)
{
const FileListNode &fileListNode = fileList->fileList[i];
totalLength+=fileListNode.dataLengthBytes;
}
// Write the chunk header, which contains the frequency table, the total number of files, and the total number of bytes
bool anythingToWrite;
outBitstream.Write((MessageID)ID_FILE_LIST_TRANSFER_HEADER);
outBitstream.Write(setID);
anythingToWrite=fileList->fileList.Size()>0;
outBitstream.Write(anythingToWrite);
if (anythingToWrite)
{
outBitstream.WriteCompressed(fileList->fileList.Size());
outBitstream.WriteCompressed(totalLength);
if (rakPeer)
rakPeer->Send(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
else
SendUnified(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
DataStructures::Queue<FileToPush*> filesToPush;
for (i=0; i < fileList->fileList.Size(); i++)
{
sendReference = fileList->fileList[i].isAReference && _incrementalReadInterface!=0;
if (sendReference)
{
FileToPush *fileToPush = SLNet::OP_NEW<FileToPush>(_FILE_AND_LINE_);
fileToPush->fileListNode.context=fileList->fileList[i].context;
fileToPush->setIndex=i;
fileToPush->fileListNode.filename=fileList->fileList[i].filename;
fileToPush->fileListNode.fullPathToFile=fileList->fileList[i].fullPathToFile;
fileToPush->fileListNode.fileLengthBytes=fileList->fileList[i].fileLengthBytes;
fileToPush->fileListNode.dataLengthBytes=fileList->fileList[i].dataLengthBytes;
// fileToPush->systemAddress=recipient;
//fileToPush->setID=setID;
fileToPush->packetPriority=priority;
fileToPush->orderingChannel=orderingChannel;
fileToPush->currentOffset=0;
fileToPush->incrementalReadInterface=_incrementalReadInterface;
fileToPush->chunkSize=_chunkSize;
filesToPush.Push(fileToPush,_FILE_AND_LINE_);
}
else
{
outBitstream.Reset();
outBitstream.Write((MessageID)ID_FILE_LIST_TRANSFER_FILE);
outBitstream << fileList->fileList[i].context;
// outBitstream.Write(fileList->fileList[i].context);
outBitstream.Write(setID);
StringCompressor::Instance()->EncodeString(fileList->fileList[i].filename, 512, &outBitstream);
outBitstream.WriteCompressed(i);
outBitstream.WriteCompressed(fileList->fileList[i].dataLengthBytes); // Original length in bytes
outBitstream.AlignWriteToByteBoundary();
dataBlocks[0]=(char*) outBitstream.GetData();
lengths[0]=outBitstream.GetNumberOfBytesUsed();
dataBlocks[1]=fileList->fileList[i].data;
lengths[1]=fileList->fileList[i].dataLengthBytes;
SendListUnified(dataBlocks,lengths,2,priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
}
}
if (filesToPush.IsEmpty()==false)
{
FileToPushRecipient *ftpr;
fileToPushRecipientListMutex.Lock();
for (i=0; i < fileToPushRecipientList.Size(); i++)
{
if (fileToPushRecipientList[i]->systemAddress==recipient && fileToPushRecipientList[i]->setId==setId)
{
// ftpr=fileToPushRecipientList[i];
// ftpr->AddRef();
// break;
RakAssert("setId already in use for this recipient" && 0);
}
}
fileToPushRecipientListMutex.Unlock();
//if (ftpr==0)
//{
ftpr = SLNet::OP_NEW<FileToPushRecipient>(_FILE_AND_LINE_);
ftpr->systemAddress=recipient;
ftpr->setId=setID;
//.........这里部分代码省略.........