Beispiel #1
0
        public ValueTask <int> SendAsync(ReadOnlyMemory <byte> memory)
        {
            RegisteredOperationEventArgs args = Interlocked.Exchange(ref _cachedSendArgs, null) ?? new RegisteredOperationEventArgs();

            (ValueTask <int> task, IntPtr requestContext, IntPtr buffersPtr) = args.Prepare(this, isSend: true, memory);
            try
            {
                lock (_requestQueue)
                {
                    Interop.Rio.Send(_requestQueue, buffersPtr, 1, 0, requestContext);
                }
            }
            catch (Exception ex)
            {
                args.Complete(ex, 0);
            }
            return(task);
        }
        private void OnNotify()
        {
            Span <Interop.Rio.RIORESULT> results = stackalloc Interop.Rio.RIORESULT[32];
            int dequeued;

            do
            {
                lock (_completionQueue)
                {
                    dequeued = Interop.Rio.DequeueCompletions(_completionQueue, results);
                }

                Console.WriteLine($"Dequeued {dequeued} notifications.");

                for (int i = 0; i < dequeued; ++i)
                {
                    ref Interop.Rio.RIORESULT result = ref results[i];
                    RegisteredOperationEventArgs.Complete(result.Status, result.BytesTransferred, new IntPtr(result.RequestContext));
                }
            }while (dequeued != 0);

            Notify();
        }