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


C++ TCPSocket::writeAll方法代码示例

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


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

示例1: idsAndGfx


//.........这里部分代码省略.........
            mc2dbg8 << " skip poly in the end of nbrPolygons" << endl;
            nbrPolygons--;
         }
         p--;
      }

      nbrPolygons=MAX(1, nbrPolygons);
      
      mc2dbg << "Sending " << nbrPolygons << " polygons of "
             << mapGfx->getNbrPolygons() << endl;


      idsAndGfx.writeNextBool(true);        // polygons closed
      idsAndGfx.writeNextByte(0);           // PAD
      idsAndGfx.writeNextShort(nbrPolygons);// # polygons
      for (uint32 p=0; p<nbrPolygons;p++) {
         uint32 nbrCoordinates = mapGfx->getNbrCoordinates(p);
         idsAndGfx.writeNextLong(nbrCoordinates);
         for (uint32 i = 0; i < nbrCoordinates; i++) {
            idsAndGfx.writeNextLong(mapGfx->getLat(p, i));
            idsAndGfx.writeNextLong(mapGfx->getLon(p, i));
         }
      }
      
      // Send filtered gfxdata information.

      // Nbr filtering levels
      idsAndGfx.writeNextLong(nbrFiltLevels);      
      for (uint32 i = 0; i < nbrFiltLevels; i++ ) {
         // Nbr polygons already written before
         for (uint32 j = 0; j < nbrPolygons; j++ ) {
            const Stack* filtStack = theMap->getFilterStack(i,j);
            // Nbr indices in the filtering stack.
            idsAndGfx.writeNextLong(filtStack->getStackSize());
            for (uint32 k = 0; k < filtStack->getStackSize(); k++) {
               // Index
               idsAndGfx.writeNextLong(filtStack->getElementAt(k));
            }
         }            
      }
       
      
      // Create and fill a buffer with the string items in this country
      DataBuffer stringItems(theMap->getMaximunSizeOfStringItems()*2 +
                             40000000); // length of items
      
      if (!theMap->saveStringItems(&stringItems)) {
         mc2log << error <<"Error saving string items for country" << endl;
      }


      // Create and fill buffer with items.
      
      // Nbr items. To be filled in later.
      uint32 offset = stringItems.getCurrentOffset();
      stringItems.writeNextLong(0);
      uint32 maxCountryMapZoom = 3;
      uint32 nbrItems = 0;
      for (uint32 z = 0; z < maxCountryMapZoom; z++) {
         writeItemsInZoomLevel(theMap, &stringItems, z, nbrItems);
      }
      // Fill in nbr items
      stringItems.writeLong(nbrItems, offset);
      
      
      // Create and fill buffer with version and length
      DataBuffer versionAndLengthBuffer(8);
      versionAndLengthBuffer.writeNextLong(theMap->getCreationTime());
      uint32 length = idsAndGfx.getCurrentOffset() +
                      stringItems.getCurrentOffset();
      versionAndLengthBuffer.writeNextLong(length);

      // Send the buffers via TCP
      uint32 nbrBytes = 
         socket->writeAll( versionAndLengthBuffer.getBufferAddress(),
                           versionAndLengthBuffer.getCurrentOffset() );
      mc2dbg4 << "   Sent " << nbrBytes << " with version ("
              << theMap->getCreationTime() << ") and length (" 
              << length << ")" << endl;

      nbrBytes = socket->writeAll( idsAndGfx.getBufferAddress(),
                                   idsAndGfx.getCurrentOffset() );
      mc2dbg4 << "   Sent " << nbrBytes << " with map IDs and GfxData"
              << endl;

      nbrBytes = socket->writeAll( stringItems.getBufferAddress(),
                                   stringItems.getCurrentOffset() );
      mc2dbg4<< "   Sent " << nbrBytes << " with string items"
                  << endl;

      

      // Delete the socket
      delete socket;
   }
   DEBUG2(
   mc2dbg << "GfxCountryMapGenerator sent all data for map " 
               << mapIDs[0] << ", processing time " 
               << TimeUtility::getCurrentTime()-startTime << " ms" << endl;
   );
开发者ID:FlavioFalcao,项目名称:Wayfinder-Server,代码行数:101,代码来源:GfxCountryMapGenerator.cpp

示例2: receiver


//.........这里部分代码省略.........
      }

      bool timeout = false;
      while ( _pack.getSubType() == Packet::PACKETTYPE_ACKNOWLEDGE &&
              ! timeout ) {
         AcknowledgeRequestReplyPacket* ackPack =
            static_cast<AcknowledgeRequestReplyPacket*>(&_pack);
         uint32 packtime =
            ((AcknowledgeRequestReplyPacket*)&_pack)->getETA() * 1000;
         mc2log << info << "Got ack with " << packtime << " us delay" << endl;
         if ( ackPack->getStatus() != StringTable::OK ) {
            return NULL;
         }
         timeout = !receiver.receive(&_pack, packtime);         
      }

      if ( timeout ) {
         mc2log << error << "Got timeout after receiving ack-pack" << endl;
         continue; // Go around again
      }

      if ( _pack.getSubType() != Packet::PACKETTYPE_MAPREPLY ) {
         mc2log << error << "Got packet with subtype "
                << _pack.getSubTypeAsString()
                << " when expecting loadmapreply" << endl;
         continue; // Please try again.
      }
      
      MapReplyPacket* pack = (MapReplyPacket *)&_pack;
      
      status = pack->getStatus();
      
      if ( status != StringTable::OK || pack->getMapID() != mapID ) {
         mc2log << warn << "Got status \""
                << StringTable::getString(
                   StringTable::stringCode(pack->getStatus()),
                   StringTable::ENGLISH)
                << "\"-retrying. Wanted map = "
                << mapID
                << ", got reply for map = " << pack->getMapID() << endl;
         if ( status == StringTable::MAPNOTFOUND ) {
            // Wait longer if map not found ( loading? )
            waittime = mapnotfoundwaittime; 
         }
         if ( mapID != pack->getMapID() ) {
            status = StringTable::NOT; // Keep the loop running.
         }
         continue; // Go another round in the loop.
      }

      if ( mapVersion != NULL && generatorVersion != NULL ) {
         // Set the versions so that we know what we are caching.
         mc2dbg8 << "[ModuleMap]: Version from packet "
                 << hex << pack->getMapVersion() << ":"
                 << pack->getGeneratorVersion() << dec << endl;
         *mapVersion       = pack->getMapVersion();
         *generatorVersion = pack->getGeneratorVersion();

         // Check if new map is needed.
         if ( ! pack->newMapNeeded(mapVersionToUse,
                                   generatorVersionToUse) ) {
            // Same version. Use the cached map.
            return NULL;
         } 
      }
      
      TCPsock = new TCPSocket;      
      mc2dbg4 << here << " opening socket" << endl;
      TCPsock->open();
      
      uint32 ip = pack->getReplyIP();
      uint16 port = pack->getReplyPort();
      
      if ( ! TCPsock->connect(ip, port ) ) {
         mc2log << error << "Couldn't connect to " << ip
                << ":" << port << " - retrying" << endl;
         // Set status to not ok.
         status = StringTable::NOT;
         TCPsock->close();
         delete TCPsock;
         TCPsock = NULL;                  
         continue; // Please try again.
      }
      
      // Handshaking
      mc2dbg4 << "Starting handshake" << endl;
      int length = strlen(handshake) + 1;
      if ( TCPsock->writeAll( (byte*)handshake, length ) != length ) {
         mc2log << error << here << " handshake failed " << endl;
         status = StringTable::NOT;
         TCPsock->close();
         delete TCPsock;
         TCPsock = NULL;
         continue; // Please try again.
      } else {
         mc2dbg4 << "done" << endl;
      }
   }
   return TCPsock; // Should be NULL if we failed
}
开发者ID:FlavioFalcao,项目名称:Wayfinder-Server,代码行数:101,代码来源:ModuleMap.cpp


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