Beispiel #1
0
        public override ValueTask <FlushResult> FlushAsync(CancellationToken cancellationToken)
        {
            try
            {
                while (!_buffer.IsEmpty)
                {
                    var memory = _buffer.GetOccupiedMemory();

                    _logger.LogTrace("TODO: SendStarting {bytes}", memory.Length);
                    var bytes = _socket.Send(memory);
                    _logger.LogTrace("TODO: SendComplete {bytes}", bytes);

                    _buffer.ConsumeOccupiedMemory(bytes);
                }
            }
            catch (Exception ex)
            {
                _logger.LogTrace(ex, "TODO: SendError");

                // Return FlushResult.IsCompleted true from now on
                // because we assume any write exceptions are not temporary
                _isCompleted = true;
#if NETSTANDARD2_0
                FireReaderCompleted(ex);
#endif
            }

            return(new ValueTask <FlushResult>(new FlushResult(
                                                   isCanceled: IsCanceled,
                                                   isCompleted: IsCompleted)));
        }
Beispiel #2
0
        public override ValueTask <FlushResult> FlushAsync(CancellationToken cancellationToken)
        {
            try
            {
                while (!_buffer.IsEmpty)
                {
                    var memory = _buffer.GetOccupiedMemory();

                    if (_options.HighVolumeLogging)
                    {
                        _logger.WriteStarting(_connection.ConnectionId, (int)memory.Length);
                    }

                    var bytes = _socket.Send(memory);

                    if (_options.HighVolumeLogging)
                    {
                        _logger.WriteSucceeded(_connection.ConnectionId, bytes);
                    }

                    _buffer.ConsumeOccupiedMemory(bytes);
                }
            }
            catch (TaskCanceledException)
            {
                _logger.WriteCanceled(_connection.ConnectionId);
                _isCanceled = true;
            }
            catch (Exception ex)
            {
                _logger.WriteFailed(_connection.ConnectionId, ex);

                // Return FlushResult.IsCompleted true from now on
                // because we assume any write exceptions are not temporary
                _isCompleted = true;
#if NETSTANDARD2_0
                FireReaderCompleted(ex);
#endif
            }

            return(new ValueTask <FlushResult>(new FlushResult(
                                                   isCanceled: IsCanceled,
                                                   isCompleted: IsCompleted)));
        }
        private void FlushBufferToSocket()
        {
            try
            {
                while (!_buffer.IsEmpty)
                {
                    var memory = _buffer.GetOccupiedMemory();

                    if (_options.HighVolumeLogging)
                    {
                        _logger.WriteStarting(_connection.ConnectionId, (int)memory.Length);
                    }

                    var bytes = _socket.Send(memory);

                    if (_options.HighVolumeLogging)
                    {
                        _logger.WriteSucceeded(_connection.ConnectionId, bytes);
                    }

                    _buffer.ConsumeOccupiedMemory(bytes);
                }
            }
            catch (TaskCanceledException)
            {
                _logger.WriteCanceled(_connection.ConnectionId);
                _isCanceled = true;
            }
            catch (Exception ex)
            {
                _logger.WriteFailed(_connection.ConnectionId, ex);

                // Return FlushResult.IsCompleted true from now on
                // because we assume any write exceptions are not temporary
                _isCompleted = true;
            }
        }
Beispiel #4
0
        public override void AdvanceTo(SequencePosition consumed, SequencePosition examined)
        {
            _buffer.ConsumeOccupiedMemory(consumed);

            _bufferHasUnexaminedData = _buffer.HasUnexaminedData(examined);
        }