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


C++ RawData::alloc方法代码示例

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


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

示例1: process

void Net::process()
{
   sockaddr sa;
   sa.sa_family = AF_UNSPEC;
   NetAddress srcAddress;
   RawData tmpBuffer;
   tmpBuffer.alloc(MaxPacketDataSize);

   for(;;)
   {
      socklen_t addrLen = sizeof(sa);
      S32 bytesRead = -1;

      if(udpSocket != InvalidSocket)
         bytesRead = recvfrom(udpSocket, (char *) tmpBuffer.data, MaxPacketDataSize, 0, &sa, &addrLen);

      if(bytesRead == -1)
         break;

      if(sa.sa_family == AF_INET)
         IPSocketToNetAddress((sockaddr_in *) &sa,  &srcAddress);
      else
         continue;

      if(bytesRead <= 0)
         continue;

      if(srcAddress.type == NetAddress::IPAddress &&
         srcAddress.netNum[0] == 127 &&
         srcAddress.netNum[1] == 0 &&
         srcAddress.netNum[2] == 0 &&
         srcAddress.netNum[3] == 1 &&
         srcAddress.port == netPort)
         continue;

      tmpBuffer.size = bytesRead;

      Net::smPacketReceive.trigger(srcAddress, tmpBuffer);
   }

   // process the polled sockets.  This blob of code performs functions
   // similar to WinsockProc in winNet.cc

   if (gPolledSockets.size() == 0)
      return;

   S32 optval;
   socklen_t optlen = sizeof(S32);
   S32 bytesRead;
   Net::Error err;
   bool removeSock = false;
   Socket *currentSock = NULL;
   sockaddr_in ipAddr;
   NetSocket incoming = InvalidSocket;
   char out_h_addr[1024];
   int out_h_length = 0;
   RawData readBuff;

   for (S32 i = 0; i < gPolledSockets.size();
      /* no increment, this is done at end of loop body */)
   {
      removeSock = false;
      currentSock = gPolledSockets[i];
      switch (currentSock->state)
      {
      case ::InvalidState:
         Con::errorf("Error, InvalidState socket in polled sockets  list");
         break;
      case ::ConnectionPending:
         // see if it is now connected
#ifdef TORQUE_OS_XENON
         // WSASetLastError has no return value, however part of the SO_ERROR behavior
         // is to clear the last error, so this needs to be done here.
         if( ( optval = _getLastErrorAndClear() ) == -1 ) 
#else
         if (getsockopt(currentSock->fd, SOL_SOCKET, SO_ERROR,
            (char*)&optval, &optlen) == -1)
#endif
         {
            Con::errorf("Error getting socket options: %s",  strerror(errno));

            Net::smConnectionNotify.trigger(currentSock->fd, Net::ConnectFailed);
            removeSock = true;
         }
         else
         {
            if (optval == EINPROGRESS)
               // still connecting...
               break;

            if (optval == 0)
            {
               // poll for writable status to be sure we're connected.
               bool ready = netSocketWaitForWritable(currentSock->fd,0);
               if(!ready)
                  break;

               currentSock->state = ::Connected;
               Net::smConnectionNotify.trigger(currentSock->fd, Net::Connected);
            }
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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