public override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            Interlocked.Increment(ref pendingreads);

            if (pendingreads > 1)
            {
            }
            _readBuffer = buffer;
            _readoffset = offset;
            _readCount  = count;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                if (_nextInputSegment.IsCompleted)
                {
                    return(Task.FromResult(GetNewSegment()));
                }
                else
                {
                    _readtcs = new TaskCompletionSource <int>();
                    _nextInputSegment.OnCompleted(_getNewSegmentDelegateDelegate);
                    return(_readtcs.Task);
                }
            }
            else
            {
                return(Task.FromResult(CompleteRead()));
            }
        }
Exemple #2
0
        void CompleteRead()
        {
            var tmp = _currentInputSegment;

            _currentInputSegment = _nextInputSegment;
            _currentInputSegment.GetResult();
            _nextInputSegment = tmp;
            if (_currentInputSegment.CurrentContentLength != 0)
            {
                _socket.BeginReceive(_nextInputSegment);
            }

            OnIncommingSegment(_currentInputSegment);

            if (_currentInputSegment.CurrentContentLength != 0)
            {
                if (_nextInputSegment.IsCompleted)
                {
                    CompleteRead();
                }
                else
                {
                    _nextInputSegment.OnCompleted(completeReadDelegate);
                }
            }
            else
            {
                Dispose();
            }
        }
Exemple #3
0
        public void Start()
        {
            _nextInputSegment = _nextInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _currentInputSegment = _currentInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
                CompleteRead();
            else
                _nextInputSegment.OnCompleted(completeReadDelegate);
        }
        public void Start()
        {
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Exemple #5
0
        public void Start()
        {
            _nextInputSegment    = _nextInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _currentInputSegment = _currentInputSegment ?? _socket.ReceiveBufferPool.GetBuffer();
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;
            _currentInputSegment = _nextInputSegment;
            _nextInputSegment = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
                CompleteRead();
            else
                _nextInputSegment.OnCompleted(completeReadDelegate);
        }
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;

            _currentInputSegment = _nextInputSegment;
            _nextInputSegment    = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Exemple #8
0
        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            _readBuffer = buffer;
            _readoffset = offset;
            _readCount = count;

            if (_currentContentLength == _bytesReadInCurrentSegment)
            {
                if (_nextInputSegment.IsCompleted)
                    return Task.FromResult(GetNewSegment());
                else
                {
                    _readtcs = new TaskCompletionSource<int>();
                    _nextInputSegment.OnCompleted(_getNewSegmentDelegateDelegate);
                    return _readtcs.Task;
                }
            }
            else
                return Task.FromResult(CompleteRead());

        }
Exemple #9
0
        void CompleteRead()
        {
            var tmp = _currentInputSegment;
            _currentInputSegment = _nextInputSegment;
            _currentInputSegment.GetResult();
            _nextInputSegment = tmp;
            if (_currentInputSegment.CurrentContentLength != 0)
                _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_currentInputSegment.CurrentContentLength != 0)
            {
                if (_nextInputSegment.IsCompleted)
                    CompleteRead();
                else
                    _nextInputSegment.OnCompleted(completeReadDelegate);
            }
            else {
                Dispose();
            }
        }