Пример #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 ResizeCompletionQueue(SafeRioCompletionQueueHandle queueHandle, uint queueSize)
 {
     Debug.Assert(!queueHandle.IsInvalid);
     if (!s_rioResizeCompletionQueue(queueHandle, queueSize))
     {
         throw new SocketException();
     }
 }
Пример #3
0
        public static void Notify(SafeRioCompletionQueueHandle queueHandle)
        {
            Debug.Assert(!queueHandle.IsInvalid);

            int res = s_rioNotify(queueHandle);

            if (res != (int)SocketError.Success)
            {
                throw new SocketException(res);
            }
        }
Пример #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 = 0,
                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 maxOutstandingSend)
        {
            Debug.Assert(!socket.IsInvalid);
            Debug.Assert(!completionQueue.IsInvalid);

            SafeRioRequestQueueHandle queue = s_rioCreateRequestQueue(socket, maxOutstandingReceive, MaxReceiveDataBuffers: 1, maxOutstandingSend, MaxSendDataBuffers: 1, completionQueue, completionQueue, context);

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

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