public UdpStream Acquire() { UdpStream stream = null; lock (pool) { if (pool.Count > 0) { stream = pool.Pop(); } } if (stream == null) { stream = new UdpStream(new byte[socket.Config.PacketSize * 2]); stream.Pool = this; } UdpAssert.Assert(stream.IsPooled); stream.IsPooled = false; stream.Position = 0; stream.Size = (socket.Config.PacketSize - UdpMath.BytesRequired(UdpSocket.HeaderBitSize)) << 3; return(stream); }
bool SendStream(UdpStream stream, UdpHandle handle, bool expandToMtu) { int bytesToSend = UdpMath.BytesRequired(stream.Ptr); if (bytesToSend < mtu && expandToMtu) { bytesToSend = mtu; } sendTime = handle.SendTime; sendSequence = handle.ObjSequence; sendWindow.Enqueue(handle); recvSinceLastSend = 0; return(socket.Send(endpoint, stream.Data, bytesToSend)); }
void SendRefusedCommand(UdpEndPoint endpoint) { UdpStream stream = GetWriteStream(Config.PacketSize << 3, HeaderBitSize); stream.WriteByte((byte)UdpCommandType.Refused, 8); UdpHeader header = new UdpHeader(); header.IsObject = false; header.AckHistory = 0; header.AckSequence = 1; header.ObjSequence = 1; header.Now = 0; header.Pack(stream, this); if (Send(endpoint, stream.Data, UdpMath.BytesRequired(stream.Ptr)) == false) { // do something here? } }
void SendRefusedCommand(UdpEndPoint endpoint) { UdpBitStream stream = new UdpBitStream(GetWriteBuffer(), Config.DefaultMtu, UdpHeader.GetSize(this)); stream.WriteByte((byte)UdpCommandType.Refused, 8); UdpHeader header = new UdpHeader(); header.IsObject = false; header.AckHistory = 0; header.AckSequence = 1; header.ObjSequence = 1; header.Now = 0; header.Pack(new UdpBitStream(stream.Data, Config.DefaultMtu, 0), this); if (Send(endpoint, stream.Data, UdpMath.BytesRequired(stream.Ptr)) == false) { // do something here? } }