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


C++ MessageBuffer类代码示例

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


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

示例1: sendClientConnect

void CheriaServer::sendClientConnect(ProtocolServer::ClientState* sourceCs,ProtocolServer::ClientState* destCs,Comm::NetPipe& pipe)
	{
	/* Get handles on the Cheria state objects: */
	ClientState* mySourceCs=dynamic_cast<ClientState*>(sourceCs);
	ClientState* myDestCs=dynamic_cast<ClientState*>(destCs);
	if(mySourceCs==0||myDestCs==0)
		Misc::throwStdErr("CheriaServer::sendClientConnect: Client state object has mismatching type");
	
	#if DEBUGGING
	std::cout<<"CheriaServer::sendClientConnect..."<<std::flush;
	#endif
	
	/* Create a temporary message buffer with the same endianness as the pipe's write end: */
	MessageBuffer buffer;
	buffer.setSwapOnWrite(pipe.mustSwapOnWrite());
	
	/*********************************************************************
	Assemble the update message in the temporary buffer:
	*********************************************************************/
	
	/* Send creation messages for the source client's devices to the destination client: */
	for(ClientDeviceMap::Iterator cdIt=mySourceCs->clientDevices.begin();!cdIt.isFinished();++cdIt)
		{
		writeMessage(CREATE_DEVICE,buffer);
		buffer.write<Card>(cdIt->getSource());
		cdIt->getDest()->writeLayout(buffer);
		}
	
	/* Send creation messages for the source client's tools to the destination client: */
	for(ClientToolMap::Iterator ctIt=mySourceCs->clientTools.begin();!ctIt.isFinished();++ctIt)
		{
		writeMessage(CREATE_TOOL,buffer);
		buffer.write<Card>(ctIt->getSource());
		ctIt->getDest()->write(buffer);
		}
	
	/* Send the current states of the source client's devices: */
	writeMessage(DEVICE_STATES,buffer);
	for(ClientDeviceMap::Iterator cdIt=mySourceCs->clientDevices.begin();!cdIt.isFinished();++cdIt)
		{
		/* Send a device state message: */
		buffer.write<Card>(cdIt->getSource());
		cdIt->getDest()->write(DeviceState::FULL_UPDATE,buffer);
		}
	buffer.write<Card>(0);
	
	/*********************************************************************
	Send the assembled message to the client in one go:
	*********************************************************************/
	
	#if DEBUGGING
	std::cout<<" message size "<<buffer.getDataSize()<<std::endl;
	#endif
	
	/* Write the message's total size first: */
	pipe.write<Card>(buffer.getDataSize());
	
	/* Write the message itself: */
	buffer.writeToSink(pipe);
	}
开发者ID:KeckCAVES,项目名称:CollaborationInfrastructure,代码行数:60,代码来源:CheriaServer.cpp

示例2: PartialProcessPacket

inline bool PartialProcessPacket(Battlenet::Session* session, MessageBuffer& inputBuffer)
{
    MessageBuffer& buffer = session->*outputBuffer;

    // We have full read header, now check the data payload
    if (buffer.GetRemainingSpace() > 0)
    {
        // need more data in the payload
        std::size_t readDataSize = std::min(inputBuffer.GetActiveSize(), buffer.GetRemainingSpace());
        buffer.Write(inputBuffer.GetReadPointer(), readDataSize);
        inputBuffer.ReadCompleted(readDataSize);
    }

    if (buffer.GetRemainingSpace() > 0)
    {
        // Couldn't receive the whole data this time.
        ASSERT(inputBuffer.GetActiveSize() == 0);
        return false;
    }

    // just received fresh new payload
    if (!(session->*processMethod)())
    {
        session->CloseSocket();
        return false;
    }

    return true;
}
开发者ID:Diyvol,项目名称:TrinityCore,代码行数:29,代码来源:Session.cpp

示例3: MessageException

MessageBuffer *Session::ReadMessage() {
	unsigned char len_buf[4];
	unsigned char *buf = NULL;
	unsigned long msg_len;
	read_monitor.Enter();
	try {
		if (ReadData(len_buf, 0, 4) != 4)
			throw MessageException("Unable to read data");
		unsigned long msg_len_net = *((unsigned int *)len_buf);
		msg_len = ntohl(msg_len_net);
		buf = new unsigned char[msg_len];
		if (ReadData(buf, 0, msg_len) != msg_len)
			throw MessageException("Unable to read data");
	} catch (...) {
		read_monitor.Exit();
		if (buf != NULL)
			delete[] buf;
		throw;
	}
	read_monitor.Exit();

	MessageBuffer *rv = new MessageBuffer();
	try {
		rv->SetData(buf, msg_len);
	} catch (...) {
		delete[] buf;
		delete rv;
		throw;
	}
	delete[] buf;
	return rv;
}
开发者ID:54k,项目名称:MultiversePlatform,代码行数:32,代码来源:Session.cpp

示例4: TellMasterThatWorkerStartedAWorkUnit

void TellMasterThatWorkerStartedAWorkUnit( MessageBuffer &mb, CDSInfo *pInfo, WUIndexType iWU )
{
    mb.setLen( 0 );
    PrepareDistributeWorkHeader( &mb, DW_SUBPACKETID_WU_STARTED );
    mb.write( &iWU, sizeof( iWU ) );
    VMPI_SendData( mb.data, mb.getLen(), VMPI_MASTER_ID, k_eVMPISendFlags_GroupPackets );
}
开发者ID:steadyfield,项目名称:SourceEngine2007,代码行数:7,代码来源:vmpi_distribute_work.cpp

示例5: PreDistributeWorkSync

void PreDistributeWorkSync( CDSInfo *pInfo )
{
    if ( g_bMPIMaster )
    {
        // Send a message telling all the workers we're ready to go on this DistributeWork call.
        MessageBuffer mb;
        PrepareDistributeWorkHeader( &mb, DW_SUBPACKETID_MASTER_READY );
        VMPI_SendData( mb.data, mb.getLen(), VMPI_PERSISTENT );
    }
    else
    {
        if ( g_iVMPIVerboseLevel >= 1 )
            Msg( "PreDistributeWorkSync: waiting for master\n" );

        // Wait for the master's message saying it's ready to go.
        while ( g_iMasterReadyForDistributeWorkCall < g_iCurDSInfo )
        {
            VMPI_DispatchNextMessage();
        }

        if ( g_iVMPIVerboseLevel >= 1 )
            Msg( "PreDistributeWorkSync: master ready\n" );

        // Now tell the master we're ready.
        MessageBuffer mb;
        PrepareDistributeWorkHeader( &mb, DW_SUBPACKETID_WORKER_READY );
        VMPI_SendData( mb.data, mb.getLen(), VMPI_MASTER_ID );
    }
}
开发者ID:steadyfield,项目名称:SourceEngine2007,代码行数:29,代码来源:vmpi_distribute_work.cpp

示例6: compute_info

 // Called when the metadata object is about to be written
 // FIll the fields on the metadata
 virtual void compute_info(const MessageBuffer& buffer)
 {
     ProcessingStep& p = *_processing_step;
     
     p.set_name("root2a4");
 
     p.set_walltime((chrono::steady_clock::now() - _start_wallclock).count());
     p.set_cputime((chrono::thread_clock::now() - _start_cpuclock).count());
     
     p.set_input_events(_input_events);
     p.set_input_bytes_read(_input_bytes_read);
     
     _metadata.set_event_count(buffer.size());
     
     if (buffer.size() >= 1) {
         if (_field_run) {
             auto run_number = _refl->GetUInt32(*buffer[0], _field_run);
             _metadata.add_run(run_number);
             
             auto* full_period = get_period(run_number);
             std::string period = full_period;
             
             if (period != "UNK") {
                 period = period[0];
             }
             
             _metadata.add_period(period);
             _metadata.add_subperiod(full_period);
         }
         if (_field_mc_channel && _refl->HasField(*buffer[0], _field_mc_channel)) 
             _metadata.add_mc_channel(_refl->GetUInt32(*buffer[0], _field_mc_channel));
     }
 }
开发者ID:JohannesEbke,项目名称:a4,代码行数:35,代码来源:main.cpp

示例7: process_messages

  void LedHandler::process_messages()
  {
      MessageBuffer* buf = _blk->getBuffer();
    //  cout << "led process" <<endl;
      google::protobuf::Message* cur = buf->remove_head();
      while(cur != 0)
      {
	  if(cur->GetTypeName() != "LedChangeMessage")
	  {
	      cout << "not led" << endl;
	      delete cur;
	      cur = buf->remove_head();
	      continue;
	  }

	  LedChangeMessage* led_change = (LedChangeMessage*)cur;

	  for(int i = 0; i < led_change->leds_size(); i++)
	  {

	      setLed(led_change->leds(i).chain(),led_change->leds(i).color());

	  }

	  delete cur;
	  cur = buf->remove_head();

      }


  }
开发者ID:cbm,项目名称:KArch,代码行数:31,代码来源:LedHandler.cpp

示例8: Deliver

void ChatRoom::Deliver(const ChatMessage& chat)
{
    MessageBuffer msgs;
    auto ptr = std::unique_ptr<Message>(new ChatMessage(chat));
    msgs.Push(ptr);

    for (auto& user : _users)
        user->Deliver(msgs);
}
开发者ID:gheckman,项目名称:GenericMudd,代码行数:9,代码来源:MuddServer.cpp

示例9: write

bool Netstream::write(const std::string &data)
{
	MessageBuffer msg;
	if (msg.set_body_length(data.size())) {
		memcpy(msg.body(), data.c_str(), data.size());
		boost::asio::async_write(sock_, boost::asio::buffer(msg.data(), msg.length()), boost::bind(&Netstream::handle_write, this, boost::asio::placeholders::error));
		return true;
	}
	return false;
}
开发者ID:chengchen09,项目名称:rpc,代码行数:10,代码来源:netstream.cpp

示例10: ProcessMessage

void MuddComm::ProcessMessage(const TimeMessage& timeMsg)
{
    MessageBuffer msgs;
    auto now = time(0);
    auto s = ctime(&now);
    auto timeChat = std::unique_ptr<Message>(new ChatMessage(s));
    
    msgs.Push(timeChat);

    Deliver(msgs);
}
开发者ID:gheckman,项目名称:GenericMudd,代码行数:11,代码来源:MuddServer.cpp

示例11: SendQDirInfo

void SendQDirInfo()
{
	char cPacketID[2] = { VMPI_SHARED_PACKET_ID, VMPI_SUBPACKETID_DIRECTORIES };

	MessageBuffer mb;
	mb.write( cPacketID, 2 );
	mb.write( gamedir, strlen( gamedir ) + 1 );
	mb.write( qdir, strlen( qdir ) + 1 );

	VMPI_SendData( mb.data, mb.getLen(), VMPI_PERSISTENT );
}
开发者ID:AluminumKen,项目名称:hl2sb-src,代码行数:11,代码来源:vmpi_tools_shared.cpp

示例12: AsyncRead

void WorldSocket::Start()
{
    AsyncRead();

    MessageBuffer initializer;
    ServerPktHeader header(ServerConnectionInitialize.size(), 0);
    initializer.Write(header.header, header.getHeaderLength() - 2);
    initializer.Write(ServerConnectionInitialize.c_str(), ServerConnectionInitialize.length());

    std::unique_lock<std::mutex> dummy(_writeLock, std::defer_lock);
    QueuePacket(std::move(initializer), dummy);
}
开发者ID:BlackWolfsDen,项目名称:BW_Eluna_Trinity_Cata_4.3.4,代码行数:12,代码来源:WorldSocket.cpp

示例13: SendPacket

void AuthSession::SendPacket(ByteBuffer& packet)
{
    if (!IsOpen())
        return;

    if (!packet.empty())
    {
        MessageBuffer buffer;
        buffer.Write(packet.contents(), packet.size());
        QueuePacket(std::move(buffer));
    }
}
开发者ID:Cyph3r,项目名称:LordPsyanBots,代码行数:12,代码来源:AuthSession.cpp

示例14: MessageBuffer

bool ConnectionInstance::sendRaw(string& message) {
    if (closed)
        return false;

    MessageBuffer* buffer = new MessageBuffer();
    MessagePtr outMessage(buffer);
    buffer->Set(message.data(), message.length());

    writeQueue.push_back(outMessage);
    ev_io_start(loop, writeEvent);
    return true;
}
开发者ID:Xenjin,项目名称:fserv,代码行数:12,代码来源:connection.cpp

示例15: unlock

int DbWrapper::unlock()
{
    // no unlock for system db
    if (m_uid < 5000)
        return CKM_API_SUCCESS;

    int retCode;
    RawBuffer ret = m_logic.unlockUserKey(m_uid, m_pw);
    MessageBuffer buff;
    buff.Push(ret);
    buff.Deserialize(retCode);
    return retCode;
}
开发者ID:Samsung,项目名称:ckm,代码行数:13,代码来源:ckm_db_tool.cpp


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