当前位置: 首页>>代码示例>>C++>>正文


C++ Queue::HasItems方法代码示例

本文整理汇总了C++中Queue::HasItems方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::HasItems方法的具体用法?C++ Queue::HasItems怎么用?C++ Queue::HasItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue::HasItems方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoSession

static status_t DoSession(const String aDesc, DataIO & aIO, const String & bDesc, DataIO & bIO)
{
   Queue<ByteBufferRef> outgoingBData;
   Queue<ByteBufferRef> outgoingAData;
   uint32 bIndex = 0, aIndex = 0;
   SocketMultiplexer multiplexer;

   while(true)
   {
      int aReadFD  = aIO.GetReadSelectSocket().GetFileDescriptor();
      int bReadFD  = bIO.GetReadSelectSocket().GetFileDescriptor();
      int aWriteFD = aIO.GetWriteSelectSocket().GetFileDescriptor();
      int bWriteFD = bIO.GetWriteSelectSocket().GetFileDescriptor();

      multiplexer.RegisterSocketForReadReady(aReadFD);
      multiplexer.RegisterSocketForReadReady(bReadFD);
      if (outgoingAData.HasItems()) multiplexer.RegisterSocketForWriteReady(aWriteFD);
      if (outgoingBData.HasItems()) multiplexer.RegisterSocketForWriteReady(bWriteFD);

      if (multiplexer.WaitForEvents() >= 0)
      {
         if (ReadIncomingData( aDesc, aIO, multiplexer, outgoingBData)         != B_NO_ERROR) return B_ERROR;
         if (ReadIncomingData( bDesc, bIO, multiplexer, outgoingAData)         != B_NO_ERROR) return B_ERROR;
         if (WriteOutgoingData(aDesc, aIO, multiplexer, outgoingAData, aIndex) != B_NO_ERROR) return B_ERROR;
         if (WriteOutgoingData(bDesc, bIO, multiplexer, outgoingBData, bIndex) != B_NO_ERROR) return B_ERROR;
      }
      else 
      {
         LogTime(MUSCLE_LOG_CRITICALERROR, "Error, WaitForEvents() failed!\n");
         return B_ERROR;
      }
   }
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:33,代码来源:udpproxy.cpp

示例2: DoSession

static status_t DoSession(DataIO & networkIO, DataIO & serialIO)
{
   Queue<ByteBufferRef> outgoingSerialData;
   Queue<ByteBufferRef> outgoingNetworkData;
   uint32 serialIndex = 0, networkIndex = 0;
   SocketMultiplexer multiplexer;
   while(true)
   {
      int networkReadFD  = networkIO.GetReadSelectSocket().GetFileDescriptor();
      int serialReadFD   = serialIO.GetReadSelectSocket().GetFileDescriptor();
      int networkWriteFD = networkIO.GetWriteSelectSocket().GetFileDescriptor();
      int serialWriteFD  = serialIO.GetWriteSelectSocket().GetFileDescriptor();

      multiplexer.RegisterSocketForReadReady(networkReadFD);
      multiplexer.RegisterSocketForReadReady(serialReadFD);

      if (outgoingNetworkData.HasItems()) multiplexer.RegisterSocketForWriteReady(networkWriteFD);
      if (outgoingSerialData.HasItems())  multiplexer.RegisterSocketForWriteReady(serialWriteFD);

      if (multiplexer.WaitForEvents() >= 0)
      {
         if (ReadIncomingData("network",  networkIO, multiplexer, outgoingSerialData)                != B_NO_ERROR) return B_NO_ERROR;  // tells main() to wait for the next TCP connection
         if (ReadIncomingData("serial",   serialIO,  multiplexer, outgoingNetworkData)               != B_NO_ERROR) return B_ERROR;     // tells main() to exit
         if (WriteOutgoingData("network", networkIO, multiplexer, outgoingNetworkData, networkIndex) != B_NO_ERROR) return B_NO_ERROR;  // tells main() to wait for the next TCP connection
         if (WriteOutgoingData("serial",  serialIO,  multiplexer, outgoingSerialData,  serialIndex)  != B_NO_ERROR) return B_ERROR;     // tells main() to exit
      }
      else 
      {
         LogTime(MUSCLE_LOG_CRITICALERROR, "Error, WaitForEvents() failed!\n");
         return B_ERROR;
      }
   }
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:33,代码来源:serialproxy.cpp

示例3: WriteOutgoingData

static status_t WriteOutgoingData(const String & desc, DataIO & writeIO, const SocketMultiplexer & multiplexer, Queue<ByteBufferRef> & outQ, uint32 & writeIdx)
{
   if (multiplexer.IsSocketReadyForWrite(writeIO.GetWriteSelectSocket().GetFileDescriptor()))
   {
      while(outQ.HasItems())
      {
         ByteBufferRef & firstBuf = outQ.Head();
         uint32 bufSize = firstBuf()->GetNumBytes();
         if (writeIdx >= bufSize) 
         {
            outQ.RemoveHead();
            writeIdx = 0;
         }
         else
         {
            int32 ret = writeIO.Write(firstBuf()->GetBuffer()+writeIdx, firstBuf()->GetNumBytes()-writeIdx);
            if (ret > 0)
            {
               writeIO.FlushOutput();
               LogTime(MUSCLE_LOG_TRACE, "Wrote " INT32_FORMAT_SPEC " bytes to %s:\n", ret, desc());
               LogHexBytes(MUSCLE_LOG_TRACE, firstBuf()->GetBuffer()+writeIdx, ret);
               writeIdx += ret;
            }
            else if (ret < 0) LogTime(MUSCLE_LOG_ERROR, "Error, writeIO.Write() returned %i\n", ret);
         }
      }
   }
   return B_NO_ERROR;
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:29,代码来源:udpproxy.cpp

示例4: main

// This program exercises the Ref class.
int main(void) 
{
   CompleteSetupSystem setupSystem;

   printf("sizeof(TestItemRef)=%i\n", (int)sizeof(TestItemRef));

   {
      printf("Checking queue...\n");
      Queue<TestItemRef> q;
      printf("Adding refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         TestItemRef tr(new TestItem(temp));
         ConstTestItemRef ctr(tr);
         ConstTestItemRef t2(ctr);
         q.AddTail(tr);
      }
      printf("Removing refs...\n");
      while(q.HasItems()) q.RemoveHead();
      printf("Done with queue test!\n");
   }

   {
      printf("Checking hashtable\n");
      Hashtable<String, TestItemRef> ht;
      printf("Adding refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         ht.Put(String(temp), TestItemRef(new TestItem(temp)));
      }
      printf("Removing refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         ht.Remove(String(temp));
      }
      printf("Done with hash table test!\n");
   }
    
   printf("Beginning multithreaded object usage test...\n");
   {
      const uint32 NUM_THREADS = 50;
      TestThread threads[NUM_THREADS]; 
      for (uint32 i=0; i<NUM_THREADS; i++) threads[i].StartInternalThread();
      Snooze64(SecondsToMicros(10));
      for (uint32 i=0; i<NUM_THREADS; i++) threads[i].ShutdownInternalThread();
      printf("Multithreaded object usage test complete.\n");
   }

   printf("testrefcount complete, bye!\n");
   return 0;
}
开发者ID:ruurdadema,项目名称:muscle,代码行数:55,代码来源:testrefcount.cpp


注:本文中的Queue::HasItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。