public void Dispose() { WSClient = null; }
internal DataPacketLoadStep Read(PipeStream stream, WSClient client) { if (mLoadStep == DataPacketLoadStep.None) { if (stream.Length >= 2) { byte value = (byte)stream.ReadByte(); this.FIN = (value & CHECK_B8) > 0; this.RSV1 = (value & CHECK_B7) > 0; this.RSV2 = (value & CHECK_B6) > 0; this.RSV3 = (value & CHECK_B5) > 0; this.Type = (DataPacketType)(byte)(value & 0xF); value = (byte)stream.ReadByte(); this.IsMask = (value & CHECK_B8) > 0; this.PayloadLen = (byte)(value & 0x7F); mLoadStep = DataPacketLoadStep.Header; } } if (mLoadStep == DataPacketLoadStep.Header) { if (this.PayloadLen == 127) { if (stream.Length >= 8) { Length = stream.ReadUInt64(); mLoadStep = DataPacketLoadStep.Length; } } else if (this.PayloadLen == 126) { if (stream.Length >= 2) { Length = stream.ReadUInt16(); mLoadStep = DataPacketLoadStep.Length; } } else { this.Length = this.PayloadLen; mLoadStep = DataPacketLoadStep.Length; } } if (mLoadStep == DataPacketLoadStep.Length) { if (IsMask) { if (stream.Length >= 4) { this.MaskKey = new byte[4]; stream.Read(this.MaskKey, 0, 4); mLoadStep = DataPacketLoadStep.Mask; } } else { mLoadStep = DataPacketLoadStep.Mask; } } if (mLoadStep == DataPacketLoadStep.Mask) { if (this.Length > 0 && (ulong)stream.Length >= this.Length) { var len = (int)this.Length; if (this.IsMask) { ReadMask(stream); } // Body = this.DataPacketSerializer.FrameDeserialize(this, stream); var data = client.GetFrameDataBuffer(len); stream.Read(data, 0, len); Body = new ArraySegment <byte>(data, 0, len); mLoadStep = DataPacketLoadStep.Completed; } } return(mLoadStep); }