Пример #1
0
        private void ProcessRequest(WriteRequest request)
        {
            if (request.Flush)
            {
                if (_size > 0)
                {
                    SwapMemoryAndWrite();
                }
                return;
            }

            var span = _memory.AsSpan(_size);

            if (request.Writer.TryWrite(span, request.Args, request.Activity, request.Timestamp, out int bytesWritten))
            {
                _size += bytesWritten;

                // If there's less space remaining than was just used, write the data out now
                if (_bufferSize - _size < bytesWritten)
                {
                    SwapMemoryAndWrite();
                }

                return;
            }

            if (_size == 0)
            {
                if (_bufferSize >= _maxBufferSize)
                {
                    return;
                }
                _bufferSize *= 2;
            }

            SwapMemoryAndWrite();

            // ReSharper disable once TailRecursiveCall
            // Because this tail call should be eliminated by RyuJIT(?)
            ProcessRequest(request);
        }
Пример #2
0
        private void ProcessRequest(WriteRequest request)
        {
            if (request.FlushSentinel && _size > 0)
            {
                SwapMemoryAndWrite();
                return;
            }

            if (_bufferSize - _size < request.Writer.LongestWritten)
            {
                SwapMemoryAndWrite();
            }

            try
            {
                var span = _memory.AsSpan(_size);

                if (request.Writer.TryWrite(span, request.Args, request.Activity, request.Timestamp,
                                            out int bytesWritten))
                {
                    _size += bytesWritten;
                    return;
                }

                IncreaseNextBufferSize();
                SwapMemoryAndWrite();
            }
            catch (Exception ex)
            {
                _errorCallback?.Invoke(ex);
            }

            // ReSharper disable once TailRecursiveCall
            // Because this tail call should be eliminated by RyuJIT(?)
            ProcessRequest(request);
        }
Пример #3
0
 public ValueTask RequestAsync(WriteRequest request, CancellationToken token = default) =>
 _requests.Writer.WriteAsync(request, token);
Пример #4
0
 public bool TryRequest(WriteRequest request) => _requests.Writer.TryWrite(request);