bool WorldSocket::SendPacket(const WorldPacket& pct) { if (IsClosed()) return false; // Dump outgoing packet. sLog.outWorldPacketDump(native_handle(), pct.GetOpcode(), pct.GetOpcodeName(), &pct, false); ServerPktHeader header(pct.size() + 2, pct.GetOpcode()); crypt_.EncryptSend((uint8*) header.header, header.getHeaderLength()); GuardType Guard(out_buffer_lock_); if (out_buffer_->space() >= pct.size() + header.getHeaderLength()) { // Put the packet on the buffer. if (!out_buffer_->Write(header.header, header.getHeaderLength())) MANGOS_ASSERT(false); if (!pct.empty() && !out_buffer_->Write(pct.contents(), pct.size())) MANGOS_ASSERT(false); } else { // Enqueue the packet. throw std::exception("network write buffer is too small to accommodate packet"); } StartAsyncSend(); return true; }
bool RASocket::SendPacket(const char* buf, size_t len) { GuardType Guard(out_buffer_lock_); if (out_buffer_->Write((uint8*)buf, len)) { StartAsyncSend(); return true; } else sLog.outError("network write buffer is too small to accommodate packet"); return false; }
void Socket::OnWriteComplete(const boost::system::error_code& error, size_t bytes_transferred) { if (error) { OnError(error); return; } GuardType Lock(out_buffer_lock_); write_operation_ = false; out_buffer_->Consume(bytes_transferred); out_buffer_->Prepare(); StartAsyncSend(); }