コード例 #1
0
        public void SetDependencies(SafeSocketHandle socket, SafeRioCompletionQueueHandle completionQueue)
        {
            bool socketAddRefSuccess          = false;
            bool completionQueueAddRefSuccess = false;

            try
            {
                socket.DangerousAddRef(ref socketAddRefSuccess);
                completionQueue.DangerousAddRef(ref completionQueueAddRefSuccess);
            }
            catch
            {
                if (socketAddRefSuccess)
                {
                    socket.DangerousRelease();
                }
                if (completionQueueAddRefSuccess)
                {
                    completionQueue.DangerousRelease();
                }
                throw;
            }

            _socket          = socket;
            _completionQueue = completionQueue;
        }
コード例 #2
0
        public static void Notify(SafeRioCompletionQueueHandle queueHandle)
        {
            int res = s_rioNotify(queueHandle);

            if (res != 0)
            {
                throw new SocketException(res);
            }
        }
コード例 #3
0
        public RegisteredMultiplexer(uint queueSize)
        {
            Interop.Rio.Init();

            _waitHandle           = new AutoResetEvent(false);
            _completionQueue      = Interop.Rio.CreateCompletionQueue(queueSize, _waitHandle.SafeWaitHandle);
            _registeredWaitHandle = ThreadPool.UnsafeRegisterWaitForSingleObject(_waitHandle,
                                                                                 (state, timedOut) => ((RegisteredMultiplexer)state).OnNotify(), this, -1, false);

            Notify();
        }
コード例 #4
0
        public static int DequeueCompletions(SafeRioCompletionQueueHandle queue, Span <RIORESULT> results)
        {
            Debug.Assert(!queue.IsInvalid);

            int res = s_rioDequeueCompletion(queue, ref MemoryMarshal.GetReference(results), results.Length);

            if (res == RIO_CORRUPT_CQ)
            {
                throw new Exception("RIO completion queue is corrupt.");
            }

            return(res);
        }
コード例 #5
0
        public static SafeRioCompletionQueueHandle CreateCompletionQueue(uint queueSize, SafeWaitHandle waitHandle)
        {
            Debug.Assert(queueSize > 0);
            Debug.Assert(waitHandle != null);

            var rnc = new RIO_NOTIFICATION_COMPLETION
            {
                Type        = RIO_EVENT_COMPLETION,
                EventHandle = waitHandle.DangerousGetHandle(),
                NotifyReset = true,
                Padding     = IntPtr.Zero
            };

            SafeRioCompletionQueueHandle handle = s_rioCreateCompletionQueue(queueSize, ref rnc);

            if (handle.IsInvalid)
            {
                throw new SocketException();
            }

            handle.SetDependencies(waitHandle);
            return(handle);
        }
コード例 #6
0
        public static SafeRioRequestQueueHandle CreateRequestQueue(SafeSocketHandle socket, SafeRioCompletionQueueHandle completionQueue, IntPtr context, uint maxOutstandingReceive, uint maxReceiveDataBuffers, uint maxOutstandingSend, uint maxSendDataBuffers)
        {
            Debug.Assert(!socket.IsInvalid);
            Debug.Assert(!completionQueue.IsInvalid);

            SafeRioRequestQueueHandle queue = s_rioCreateRequestQueue(socket, maxOutstandingReceive, maxReceiveDataBuffers, maxOutstandingSend, maxSendDataBuffers, completionQueue, completionQueue, context);

            if (queue.IsInvalid)
            {
                throw new SocketException();
            }

            queue.SetDependencies(socket, completionQueue);
            return(queue);
        }