public async static Task WriteMemoryStreamToAsync(ushort RequestId, FastCGI.PacketType PacketType, MemoryStream From, Stream ClientStream) { var Buffer = From.GetBuffer(); var BufferRealLength = (int)From.Length; for (int n = 0; n < BufferRealLength; n += ushort.MaxValue) { await new FastCGIPacket() { RequestId = RequestId, Type = PacketType, Content = new ArraySegment <byte>(Buffer, n, Math.Min(ushort.MaxValue, BufferRealLength - n)), }.WriteToAsync(ClientStream); } }
public async Task<FastCGIPacket> ReadFromAsync(Stream ClientStream) { var Header = new byte[8]; await ClientStream.ReadAsync(Header, 0, Header.Length); var Version = Header[0]; Type = (FastCGI.PacketType)Header[1]; RequestId = (ushort)((Header[2] << 8) | (Header[3] << 0)); var ContentLength = (ushort)((Header[4] << 8) | (Header[5] << 0)); var PaddingLength = Header[6]; Content = new ArraySegment<byte>(new byte[ContentLength]); if (ContentLength + PaddingLength > 0) { await ClientStream.ReadAsync(Content.Array, 0, ContentLength); await ClientStream.ReadAsync(PaddingRead, 0, PaddingLength); } return this; }
public async Task <FastCGIPacket> ReadFromAsync(Stream ClientStream) { var Header = new byte[8]; await ClientStream.ReadAsync(Header, 0, Header.Length); var Version = Header[0]; Type = (FastCGI.PacketType)Header[1]; RequestId = (ushort)((Header[2] << 8) | (Header[3] << 0)); var ContentLength = (ushort)((Header[4] << 8) | (Header[5] << 0)); var PaddingLength = Header[6]; Content = new ArraySegment <byte>(new byte[ContentLength]); if (ContentLength + PaddingLength > 0) { await ClientStream.ReadAsync(Content.Array, 0, ContentLength); await ClientStream.ReadAsync(PaddingRead, 0, PaddingLength); } return(this); }