Example #1
0
 private void WriteEOFPackage()
 {
     _packagePipe.Write(null);
 }
Example #2
0
        private bool ReaderBuffer(ReadOnlySequence <byte> buffer, out SequencePosition consumed, out SequencePosition examined)
        {
            consumed = buffer.Start;
            examined = buffer.End;

            var maxPackageLength = Options.MaxPackageLength;

            var seqReader = new SequenceReader <byte>(buffer);

            while (true)
            {
                var currentPipelineFilter = _pipelineFilter;

                var packageInfo = currentPipelineFilter.Filter(ref seqReader);

                if (currentPipelineFilter.NextFilter != null)
                {
                    _pipelineFilter = currentPipelineFilter.NextFilter;
                }

                var len = seqReader.Consumed;

                // nothing has been consumed, need more data
                if (len == 0)
                {
                    len = seqReader.Length;
                }

                if (maxPackageLength > 0 && len > maxPackageLength)
                {
                    Logger.LogError($"Package cannot be larger than {maxPackageLength}.");
                    // close the the connection directly
                    Close();
                    _packagePipe.Write(null);
                    return(false);
                }

                // continue receive...
                if (packageInfo == null)
                {
                    return(true);
                }

                currentPipelineFilter.Reset();

                _packagePipe.Write(packageInfo);

                if (seqReader.End) // no more data
                {
                    consumed = buffer.End;
                    break;
                }
                else
                {
                    examined  = consumed = seqReader.Position;
                    seqReader = new SequenceReader <byte>(seqReader.Sequence.Slice(seqReader.Consumed));
                }
            }

            return(true);
        }