Example #1
0
 public void AddConnection(long key, RioTcpConnection value)
 {
     lock (_connections)
     {
         _connections.Add(key, value);
     }
 }
Example #2
0
        private void ProcessPhysicalCompletions()
        {
            RioRequestResult *results = stackalloc RioRequestResult[maxResults];
            var connectionsToSignal   = new RioTcpConnection[maxResults];

            _rio.Notify(ReceiveCompletionQueue);
            while (!_token.IsCancellationRequested)
            {
                var success = GetQueuedCompletionStatus(CompletionPort, out uint bytes, out uint key, out NativeOverlapped * 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;
                        }

                        Complete(results, count, connectionsToSignal);

                        Notify(connectionsToSignal, count);

                        if (!activatedNotify)
                        {
                            activatedNotify = true;
                            _rio.Notify(ReceiveCompletionQueue);
                        }
                    }
                }
                else
                {
                    var error = GetLastError();
                    if (error != 258)
                    {
                        throw new Exception($"ERROR: GetQueuedCompletionStatusEx returned {error}");
                    }
                }
            }
        }
Example #3
0
 private static async Task ProcessRIOConnection <TContext>(IHttpApplication <TContext> application, RioTcpConnection connection)
 {
     using (connection)
     {
         await ProcessClient(application, connection);
     }
 }
Example #4
0
        private void ProcessPhysicalCompletions()
        {
            RioRequestResult* results = stackalloc RioRequestResult[maxResults];
            var connectionsToSignal = new RioTcpConnection[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;
                        }

                        Complete(results, count, connectionsToSignal);

                        Notify(connectionsToSignal, count);

                        if (!activatedNotify)
                        {
                            activatedNotify = true;
                            _rio.Notify(ReceiveCompletionQueue);

                        }
                    }
                }
                else
                {
                    var error = GetLastError();
                    if (error != 258)
                    {
                        throw new Exception($"ERROR: GetQueuedCompletionStatusEx returned {error}");
                    }
                }
            }
        }
Example #5
0
        private unsafe void Complete(RioRequestResult* results, uint count, RioTcpConnection[] connectionsToSignal)
        {
            for (var i = 0; i < count; i++)
            {
                var result = results[i];

                RioTcpConnection connection;
                bool found;
                lock (_connections)
                {
                    found = _connections.TryGetValue(result.ConnectionCorrelation, out connection);
                }

                if (found)
                {
                    if (result.RequestCorrelation >= 0)
                    {
                        connection.ReceiveBeginComplete(result.BytesTransferred);
                        connectionsToSignal[i] = connection;
                    }
                    else
                    {
                        connection.SendComplete(result.RequestCorrelation);
                        connectionsToSignal[i] = null;
                    }
                }
                else
                {
                    connectionsToSignal[i] = null;
                }
            }
        }
Example #6
0
        private static void Notify(RioTcpConnection[] connectionsToSignal, uint count)
        {
            for (var i = 0; i < connectionsToSignal.Length; i++)
            {
                if (i >= count)
                {
                    break;
                }

                var connection = connectionsToSignal[i];

                if (connection != null)
                {
                    connection.ReceiveEndComplete();
                    connectionsToSignal[i] = null;
                }
            }
        }