Exemplo n.º 1
0
            // Connection callback from Libuv thread
            void IServerNativeUnsafe.Accept(RemoteConnection connection)
            {
                var          ch     = _channel;
                NativeHandle client = connection.Client;

                var connError = connection.Error;

                // If the AutoRead is false, reject the connection
                if (!ch._config.AutoRead || connError is object)
                {
                    if (connError is object)
                    {
                        if (Logger.InfoEnabled)
                        {
                            Logger.AcceptClientConnectionFailed(connError);
                        }
                        _ = _channel.Pipeline.FireExceptionCaught(connError);
                    }
                    try
                    {
                        client?.Dispose();
                    }
                    catch (Exception ex)
                    {
                        if (Logger.WarnEnabled)
                        {
                            Logger.FailedToDisposeAClientConnection(ex);
                        }
                    }
                    finally
                    {
                        client = null;
                    }
                }
                if (client is null)
                {
                    return;
                }

                if (ch.EventLoop is DispatcherEventLoop dispatcher)
                {
                    // Dispatch handle to other Libuv loop/thread
                    dispatcher.Dispatch(client);
                }
                else
                {
                    Accept((Tcp)client);
                }
            }