本文整理汇总了C++中MessageBuffer::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageBuffer::Write方法的具体用法?C++ MessageBuffer::Write怎么用?C++ MessageBuffer::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBuffer
的用法示例。
在下文中一共展示了MessageBuffer::Write方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
bool WorldSocket::Update()
{
EncryptablePacket* queued;
MessageBuffer buffer;
while (_bufferQueue.Dequeue(queued))
{
ServerPktHeader header(queued->size() + 2, queued->GetOpcode());
if (queued->NeedsEncryption())
_authCrypt.EncryptSend(header.header, header.getHeaderLength());
if (buffer.GetRemainingSpace() < queued->size() + header.getHeaderLength())
{
QueuePacket(std::move(buffer));
buffer.Resize(4096);
}
if (buffer.GetRemainingSpace() >= queued->size() + header.getHeaderLength())
{
buffer.Write(header.header, header.getHeaderLength());
if (!queued->empty())
buffer.Write(queued->contents(), queued->size());
}
else // single packet larger than 4096 bytes
{
MessageBuffer packetBuffer(queued->size() + header.getHeaderLength());
packetBuffer.Write(header.header, header.getHeaderLength());
if (!queued->empty())
packetBuffer.Write(queued->contents(), queued->size());
QueuePacket(std::move(packetBuffer));
}
delete queued;
}
if (buffer.GetActiveSize() > 0)
QueuePacket(std::move(buffer));
if (!BaseSocket::Update())
return false;
if (_queryFuture.valid() && _queryFuture.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
auto callback = _queryCallback;
_queryCallback = nullptr;
callback(_queryFuture.get());
}
return true;
}
示例2: Start
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);
}
示例3: SendPacket
void AuthSession::SendPacket(ByteBuffer& packet)
{
if (!IsOpen())
return;
if (!packet.empty())
{
MessageBuffer buffer;
buffer.Write(packet.contents(), packet.size());
QueuePacket(std::move(buffer));
}
}
示例4: SendPacket
void AuthSession::SendPacket(ByteBuffer& packet)
{
if (!IsOpen())
return;
if (!packet.empty())
{
MessageBuffer buffer;
buffer.Write(packet.contents(), packet.size());
std::unique_lock<std::mutex> guard(_writeLock);
QueuePacket(std::move(buffer), guard);
}
}
示例5: WritePacketToBuffer
void WorldSocket::WritePacketToBuffer(WorldPacket const& packet, MessageBuffer& buffer)
{
ServerPktHeader header;
uint32 sizeOfHeader = SizeOfServerHeader[_authCrypt.IsInitialized()];
uint32 opcode = packet.GetOpcode();
uint32 packetSize = packet.size();
// Reserve space for buffer
uint8* headerPos = buffer.GetWritePointer();
buffer.WriteCompleted(sizeOfHeader);
if (packetSize > 0x400)
{
CompressedWorldPacket cmp;
cmp.UncompressedSize = packetSize + 4;
cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, 4), packet.contents(), packetSize);
// Reserve space for compression info - uncompressed size and checksums
uint8* compressionInfo = buffer.GetWritePointer();
buffer.WriteCompleted(sizeof(CompressedWorldPacket));
uint32 compressedSize = CompressPacket(buffer.GetWritePointer(), packet);
cmp.CompressedAdler = adler32(0x9827D8F1, buffer.GetWritePointer(), compressedSize);
memcpy(compressionInfo, &cmp, sizeof(CompressedWorldPacket));
buffer.WriteCompleted(compressedSize);
packetSize = compressedSize + sizeof(CompressedWorldPacket);
opcode = SMSG_COMPRESSED_PACKET;
}
else if (!packet.empty())
buffer.Write(packet.contents(), packet.size());
if (_authCrypt.IsInitialized())
{
header.Normal.Size = packetSize;
header.Normal.Command = opcode;
_authCrypt.EncryptSend((uint8*)&header, sizeOfHeader);
}
else
{
header.Setup.Size = packetSize + 4;
header.Setup.Command = opcode;
}
memcpy(headerPos, &header, sizeOfHeader);
}
示例6: EndianConvertReverse
void Battlenet::Session::SendResponse(uint32 token, uint32 status)
{
Header header;
header.set_token(token);
header.set_status(status);
header.set_service_id(0xFE);
uint16 headerSize = header.ByteSize();
EndianConvertReverse(headerSize);
MessageBuffer packet;
packet.Write(&headerSize, sizeof(headerSize));
uint8* ptr = packet.GetWritePointer();
packet.WriteCompleted(header.ByteSize());
header.SerializeToArray(ptr, header.ByteSize());
AsyncWrite(&packet);
}
示例7: WritePacketToBuffer
void Socket::WritePacketToBuffer(Packet const& packet, MessageBuffer& buffer)
{
ServerHeader header;
uint32 sizeOfHeader = SizeOfServerHeader;
uint32 opcode = packet.GetOpcode();
uint32 packetSize = packet.size();
// Reserve space for buffer
uint8* headerPos = buffer.GetWritePointer();
buffer.WriteCompleted(sizeOfHeader);
if (!packet.empty())
buffer.Write(packet.contents(), packet.size());
header.Size = packetSize;
header.Command = opcode;
memcpy(headerPos, &header, sizeOfHeader);
}
示例8: GetClientInfo
void Battlenet::Session::AsyncWrite(ServerPacket* packet)
{
if (!IsOpen())
{
delete packet;
return;
}
TC_LOG_DEBUG("session.packets", "%s Sending %s", GetClientInfo().c_str(), PacketToStringHelper(packet).c_str());
packet->Write();
MessageBuffer buffer;
buffer.Write(packet->GetData(), packet->GetSize());
delete packet;
std::unique_lock<std::mutex> guard(_writeLock);
_crypt.EncryptSend(buffer.GetReadPointer(), buffer.GetActiveSize());
QueuePacket(std::move(buffer), guard);
}