Esempio n. 1
0
 private void _SetPayloadWithoutCopy(byte[] arrNewPayload)
 {
     WebSocketMessage.MaskDataInPlace(arrNewPayload, this._arrMask);
     this._arrRawPayload = arrNewPayload;
 }
 public WebSocketMessageEventArgs(WebSocketMessage _inMsg)
 {
     this.oWSM = _inMsg;
 }
Esempio n. 3
0
        private static WebSocketMessage[] _ParseMessagesFromStream(WebSocket wsOwner, ref MemoryStream strmData, bool bIsOutbound, bool bTrimAfterParsing)
        {
            List <WebSocketMessage> list = new List <WebSocketMessage>();

            strmData.Position = 0L;
            long num = 0L;

            while (strmData.Length - strmData.Position >= 2L)
            {
                byte[] array = new byte[2];
                strmData.Read(array, 0, array.Length);
                ulong num2 = (ulong)((long)(array[1] & 127));
                if (num2 == 126uL)
                {
                    if (strmData.Length < strmData.Position + 2L)
                    {
                        break;
                    }
                    byte[] array2 = new byte[2];
                    strmData.Read(array2, 0, array2.Length);
                    num2 = (ulong)((long)((long)array2[0] << 8) + (long)((ulong)array2[1]));
                }
                else
                {
                    if (num2 == 127uL)
                    {
                        if (strmData.Length < strmData.Position + 8L)
                        {
                            break;
                        }
                        byte[] array3 = new byte[8];
                        strmData.Read(array3, 0, array3.Length);
                        num2 = (ulong)((long)(((int)array3[0] << 24) + ((int)array3[1] << 16) + ((int)array3[2] << 8) + (int)array3[3] + ((int)array3[4] << 24) + ((int)array3[5] << 16) + ((int)array3[6] << 8) + (int)array3[7]));
                    }
                }
                bool flag = 128 == (array[1] & 128);
                if (strmData.Length < strmData.Position + (long)num2 + (flag ? 4L : 0L))
                {
                    break;
                }
                WebSocketMessage webSocketMessage = new WebSocketMessage(wsOwner, Interlocked.Increment(ref wsOwner._iMsgCount), bIsOutbound);
                webSocketMessage.AssignHeader(array[0]);
                if (flag)
                {
                    byte[] array4 = new byte[4];
                    strmData.Read(array4, 0, array4.Length);
                    webSocketMessage.MaskingKey = array4;
                }
                byte[] array5 = new byte[num2];
                strmData.Read(array5, 0, array5.Length);
                webSocketMessage.PayloadData = array5;
                list.Add(webSocketMessage);
                num = strmData.Position;
            }
            strmData.Position = num;
            if (bTrimAfterParsing)
            {
                byte[] array6 = new byte[strmData.Length - num];
                strmData.Read(array6, 0, array6.Length);
                strmData.Dispose();
                strmData = new MemoryStream();
                strmData.Write(array6, 0, array6.Length);
            }
            return(list.ToArray());
        }