本文整理汇总了C#中PacketWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# PacketWriter.Close方法的具体用法?C# PacketWriter.Close怎么用?C# PacketWriter.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketWriter
的用法示例。
在下文中一共展示了PacketWriter.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPacketToSend
KeyValuePair<TransferBuffer, Packet> GetPacketToSend()
{
if (m_outgoing_packets.Count == 0)
{
throw (new Exception("[SecurityAPI::GetPacketToSend] No packets are avaliable to send."));
}
Packet packet = m_outgoing_packets[0];
m_outgoing_packets.RemoveAt(0);
if (packet.Massive)
{
PacketWriter final = null;
PacketWriter final_data = null;
byte[] raw_bytes = null;
PacketReader input_reader = null;
PacketWriter final_header = null;
try
{
ushort parts = 0;
final = new PacketWriter();
final_data = new PacketWriter();
byte[] input_data = packet.GetBytes();
input_reader = new PacketReader(input_data);
TransferBuffer workspace = new TransferBuffer(4089, 0, (int)input_data.Length);
while (workspace.Size > 0)
{
PacketWriter part_data = null;
try
{
part_data = new PacketWriter();
int cur_size = workspace.Size > 4089 ? 4089 : workspace.Size; // Max buffer size is 4kb for the client
part_data.Write((byte)0); // Data flag
part_data.Write(input_data, workspace.Offset, cur_size);
workspace.Offset += cur_size;
workspace.Size -= cur_size; // Update the size
final_data.Write(FormatPacket(0x600D, part_data.GetBytes(), false));
++parts; // Track how many parts there are
}
finally
{
if (part_data != null)
{
part_data.Close();
}
}
}
// Write the final header packet to the front of the packet
final_header = new PacketWriter();
final_header.Write((byte)1); // Header flag
final_header.Write((short)parts);
final_header.Write(packet.Opcode);
final.Write(FormatPacket(0x600D, final_header.GetBytes(), false));
// Finish the large packet of all the data
final.Write(final_data.GetBytes());
// Return the collated data
raw_bytes = final.GetBytes();
}
finally
{
if (final != null)
{
final.Close();
}
if (final_data != null)
{
final_data.Close();
}
if (input_reader != null)
{
input_reader.Close();
}
if (final_header != null)
{
final_header.Close();
}
}
packet.Lock();
return new KeyValuePair<TransferBuffer, Packet>(new TransferBuffer(raw_bytes, 0, raw_bytes.Length, true), packet);
}
else
{
//.........这里部分代码省略.........