private unsafe void ProcessCompletions(object state) { Thread.CurrentThread.Name = nameof(ReceiveCompletionProcessor); var completionQueue = (RioCompletionQueue)state; var maxCompletionResults = _configuration.MaxReceiveCompletionResults; var results = stackalloc RIO_RESULT[maxCompletionResults]; var waitStrategy = CompletionPollingWaitStrategyFactory.Create(_configuration.ReceiveCompletionPollingWaitStrategyType); while (_isRunning) { var resultCount = completionQueue.TryGetCompletionResults(results, maxCompletionResults); if (resultCount == 0) { waitStrategy.Wait(); continue; } waitStrategy.Reset(); for (var i = 0; i < resultCount; i++) { var result = results[i]; var sessionId = (int)result.ConnectionCorrelation; var bufferSegmentId = (int)result.RequestCorrelation; OnRequestCompletion(sessionId, bufferSegmentId, (int)result.BytesTransferred); } } }
public void OnEvent(ref RequestEntry data, long sequence, bool endOfBatch) { if (data.Type == RequestType.Receive) { return; } var waitStrategy = CompletionPollingWaitStrategyFactory.Create(_configuration.SendCompletionPollingWaitStrategyType); while (!_releasableSequences.Remove(sequence)) { var resultCount = _sendCompletionQueue.TryGetCompletionResults(_completionResultsPointer, _completionResults.Length); if (resultCount == 0) { waitStrategy.Wait(); continue; } waitStrategy.Reset(); for (var i = 0; i < resultCount; i++) { var result = _completionResultsPointer[i]; var releasableSequence = result.RequestCorrelation; _releasableSequences.Add(releasableSequence); } } data.Reset(); }
public SendCompletionProcessor(InternalZerioConfiguration configuration, IRioCompletionQueue sendCompletionQueue) { _sendCompletionQueue = sendCompletionQueue; _completionResults = new RIO_RESULT[configuration.MaxSendCompletionResults]; _completionResultsHandle = GCHandle.Alloc(_completionResults, GCHandleType.Pinned); _completionResultsPointer = (RIO_RESULT *)_completionResultsHandle.AddrOfPinnedObject().ToPointer(); _waitStrategy = CompletionPollingWaitStrategyFactory.Create(configuration.SendCompletionPollingWaitStrategyType); }