Exemplo n.º 1
0
        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()));
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void Start()
        {
            _socket.BeginReceive(_nextInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 6
0
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;
            _currentInputSegment = _nextInputSegment;
            _nextInputSegment = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
                CompleteRead();
            else
                _nextInputSegment.OnCompleted(completeReadDelegate);
        }
Exemplo n.º 7
0
        public void CompleteRead()
        {
            var tmp = _currentInputSegment;

            _currentInputSegment = _nextInputSegment;
            _nextInputSegment    = tmp;

            _socket.BeginReceive(_nextInputSegment);

            OnIncommingSegment(_currentInputSegment);

            if (_nextInputSegment.IsCompleted)
            {
                CompleteRead();
            }
            else
            {
                _nextInputSegment.OnCompleted(completeReadDelegate);
            }
        }
Exemplo n.º 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());

        }
Exemplo n.º 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();
            }
        }