private void ProcessLogicalCompletions() { RioRequestResult *results = stackalloc RioRequestResult[maxResults]; _rio.Notify(ReceiveCompletionQueue); while (!_token.IsCancellationRequested) { NativeOverlapped *overlapped; uint bytes, key; var success = GetQueuedCompletionStatus(CompletionPort, out bytes, out key, out overlapped, -1); if (success) { var activatedNotify = false; while (true) { var count = _rio.DequeueCompletion(ReceiveCompletionQueue, (IntPtr)results, maxResults); if (count == 0) { if (!activatedNotify) { activatedNotify = true; _rio.Notify(ReceiveCompletionQueue); continue; } break; } var gotBatch = false; var batch = default(NotifyBatch); lock (_processedBatches) { if (_processedBatches.Count > 0) { batch = _processedBatches.Dequeue(); batch.Count = count; gotBatch = true; } } if (!gotBatch) { batch = new NotifyBatch() { ConnectionsToSignal = new RioTcpConnection[maxResults], Count = count }; } var connectionsToSignal = batch.ConnectionsToSignal; Complete(results, count, connectionsToSignal); lock (_notify) { _notifyBatches.Enqueue(batch); Monitor.Pulse(_notify); } if (!activatedNotify) { activatedNotify = true; _rio.Notify(ReceiveCompletionQueue); } } } else { var error = GetLastError(); if (error != 258) { throw new Exception($"ERROR: GetQueuedCompletionStatusEx returned {error}"); } } } }
private void ProcessLogicalCompletions() { RioRequestResult* results = stackalloc RioRequestResult[maxResults]; _rio.Notify(ReceiveCompletionQueue); while (!_token.IsCancellationRequested) { NativeOverlapped* overlapped; uint bytes, key; var success = GetQueuedCompletionStatus(CompletionPort, out bytes, out key, out overlapped, -1); if (success) { var activatedNotify = false; while (true) { var count = _rio.DequeueCompletion(ReceiveCompletionQueue, (IntPtr)results, maxResults); if (count == 0) { if (!activatedNotify) { activatedNotify = true; _rio.Notify(ReceiveCompletionQueue); continue; } break; } var gotBatch = false; var batch = default(NotifyBatch); lock (_processedBatches) { if (_processedBatches.Count > 0) { batch = _processedBatches.Dequeue(); batch.Count = count; gotBatch = true; } } if (!gotBatch) { batch = new NotifyBatch() { ConnectionsToSignal = new RioTcpConnection[maxResults], Count = count }; } var connectionsToSignal = batch.ConnectionsToSignal; Complete(results, count, connectionsToSignal); lock (_notify) { _notifyBatches.Enqueue(batch); Monitor.Pulse(_notify); } if (!activatedNotify) { activatedNotify = true; _rio.Notify(ReceiveCompletionQueue); } } } else { var error = GetLastError(); if (error != 258) { throw new Exception($"ERROR: GetQueuedCompletionStatusEx returned {error}"); } } } }