internal ReceiveProcessor()
        {
            _currentStepReadBuffer = FrameFormat.EmptyBytes;

            _readBufferCache     = new byte[NetworkSettings.ReadBufferSize];
            _tempFrameHeaderData = new FrameHeaderData();
        }
Exemple #2
0
        internal void Reset()
        {
            _unprocessCount         = 0;
            _bufferStartIndex       = 0;
            _messageBytesReadLength = 0;

            _headerExtentionBytes = FrameFormat.EmptyBytes;
            _titleBytes           = FrameFormat.EmptyBytes;
            _contentBytes         = FrameFormat.EmptyBytes;

            _currentFrameHeaderData = null;
        }
Exemple #3
0
 internal ReceiveProcessor()
 {
     _readBuffer          = new byte[NetworkSettings.ReadBufferSize];
     _tempFrameHeaderData = new FrameHeaderData();
 }
Exemple #4
0
        internal int CheckCurrentStep(int readCount)
        {
            _messageBytesReadLength += readCount;
            _bufferStartIndex       += readCount;

            if (_currentFrameHeaderData == null)
            {
                if (_messageBytesReadLength < FrameFormat.FrameHeaderSize)
                {
                    return(0);
                }

                if (FrameFormat.CheckFrameHeader(_readBuffer) == false)
                {
                    return(-1);
                }

                var frameHeaderData = _tempFrameHeaderData;
                FrameFormat.ReadDataFromHeaderBuffer(_readBuffer, ref frameHeaderData);

                _headerExtentionLength = frameHeaderData.HeaderExtentionLength;
                _titleLength           = frameHeaderData.TitleLength;
                _contentLength         = frameHeaderData.ContentLength;
                _stateCode             = frameHeaderData.StateCode;
                _messageId             = frameHeaderData.MessageId;

                _currentFrameHeaderData = frameHeaderData;

                _headerExtentionBytes = _headerExtentionLength == 0 ? FrameFormat.EmptyBytes : new byte[_headerExtentionLength];
                _titleBytes           = _titleLength == 0 ? FrameFormat.EmptyBytes : new byte[_titleLength];
                _contentBytes         = _contentLength == 0 ? FrameFormat.EmptyBytes : new byte[_contentLength];

                if (GetBodyLength() == 0)
                {
                    return(_messageBytesReadLength == FrameFormat.FrameHeaderSize ? 1 : -1);
                }

                readCount = readCount - FrameFormat.FrameHeaderSize;
            }

            _unprocessCount += readCount;

            var messageLength = GetBodyLength() + FrameFormat.FrameHeaderSize;

            // message format error,return error code
            if (_messageBytesReadLength > messageLength)
            {
                return(-1);
            }

            // read datas and return success code
            if (_messageBytesReadLength == messageLength)
            {
                ReadBufferDatas(_unprocessCount);
                return(1);
            }

            // message is not complete,return continue-reading code
            // if buffer is full,move datas to cache and clear buffer
            if (_bufferStartIndex == _readBuffer.Length)
            {
                ReadBufferDatas(_unprocessCount);
                _unprocessCount   = 0;
                _bufferStartIndex = 0;
            }

            //continue to read
            return(0);
        }