コード例 #1
0
 public DraftHybi10DataReader()
 {
     m_Frame      = new WebSocketDataFrame(new ArraySegmentList());
     m_PartReader = DataFramePartReader.NewReader;
 }
コード例 #2
0
        public WebSocketCommandInfo GetCommandInfo(byte[] readBuffer, int offset, int length, out int left)
        {
            this.AddArraySegment(m_Frame.InnerData, readBuffer, offset, length, true);

            IDataFramePartReader nextPartReader;

            int thisLength = m_PartReader.Process(m_LastPartLength, m_Frame, out nextPartReader);

            if (thisLength < 0)
            {
                left = 0;
                return(null);
            }
            else
            {
                left = thisLength;

                if (left > 0)
                {
                    m_Frame.InnerData.TrimEnd(left);
                }

                //Means this part reader is the last one
                if (nextPartReader == null)
                {
                    WebSocketCommandInfo commandInfo;

                    if (m_Frame.FIN)
                    {
                        if (m_PreviousFrames != null && m_PreviousFrames.Count > 0)
                        {
                            m_PreviousFrames.Add(m_Frame);
                            m_Frame          = new WebSocketDataFrame(new ArraySegmentList());
                            commandInfo      = new WebSocketCommandInfo(m_PreviousFrames);
                            m_PreviousFrames = null;
                        }
                        else
                        {
                            commandInfo = new WebSocketCommandInfo(m_Frame);
                            m_Frame.Clear();
                        }
                    }
                    else
                    {
                        if (m_PreviousFrames == null)
                        {
                            m_PreviousFrames = new List <WebSocketDataFrame>();
                        }

                        m_PreviousFrames.Add(m_Frame);
                        m_Frame = new WebSocketDataFrame(new ArraySegmentList());

                        commandInfo = null;
                    }

                    //BufferSegments.ClearSegements();
                    m_LastPartLength = 0;
                    m_PartReader     = DataFramePartReader.NewReader;

                    return(commandInfo);
                }
                else
                {
                    m_LastPartLength = m_Frame.InnerData.Count - thisLength;
                    m_PartReader     = nextPartReader;

                    return(null);
                }
            }
        }