コード例 #1
0
ファイル: HostingEngineTests.cs プロジェクト: webdior/Hosting
        public IDisposable Start(IServerInformation serverInformation, Func <object, Task> application)
        {
            var startInstance = new StartInstance(application);

            _startInstances.Add(startInstance);
            return(startInstance);
        }
コード例 #2
0
        public ServerPacketProcessor(ServerBuilderOptions options,
                                     ILogger <ServerPacketProcessor> logger,
                                     IPacketHandlers packetHandlers,
                                     IServerInformation serverInformation,
                                     IPacketSerialiser packetSerialiser,
                                     IEnumerable <IMiddlewareHandler> middlewares)
        {
            this.logger            = logger;
            this.packetHandlers    = packetHandlers;
            this.serverInformation = serverInformation;
            this.packetSerialiser  = packetSerialiser;
            this.middlewares       = middlewares.ToList();

            tcpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections);

            for (var i = 0; i < tcpSenderObjectPool.Capacity; i++)
            {
                tcpSenderObjectPool.Push(new TcpSender(packetSerialiser));
            }

            udpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections * 2);

            for (var i = 0; i < udpSenderObjectPool.Capacity; i++)
            {
                udpSenderObjectPool.Push(new UdpSender(_socketSender));
            }

            packetContextObjectPool = new ObjectPool <IPacketContext>(options.TcpMaxConnections * 2);

            for (var i = 0; i < packetContextObjectPool.Capacity; i++)
            {
                packetContextObjectPool.Push(new PacketContext());
            }
        }
コード例 #3
0
        private static SqlServerVersion GetTargetServerVersion(IServerInformation srv)
        {
            var version = srv.VersionMajor + srv.VersionMinor.ToString();

            if (version == "80")
            {
                return(SqlServerVersion.Version80);
            }

            if (version == "90")
            {
                return(SqlServerVersion.Version90);
            }

            if (version == "100")
            {
                return(SqlServerVersion.Version100);
            }

            if (version == "1050")
            {
                return(SqlServerVersion.Version105);
            }

            throw new Exception("Unsupported Server Version");
        }
コード例 #4
0
 public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
 {
     var disposables = new List<IDisposable>();
     var information = (ServerInformation)serverInformation;
     var engine = new KestrelEngine(_libraryManager, _appShutdownService);
     engine.Start(1);
     foreach (var address in information.Addresses)
     {
         disposables.Add(engine.CreateServer(
             address.Scheme,
             address.Host,
             address.Port,
             async frame =>
             {
                 var request = new ServerRequest(frame);
                 await application.Invoke(request.Features);
             }));
     }
     disposables.Add(engine);
     return new Disposable(() =>
     {
         foreach (var disposable in disposables)
         {
             disposable.Dispose();
         }
     });
 }
コード例 #5
0
        public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application)
        {
            var disposables = new List <IDisposable>();
            var information = (ServerInformation)serverInformation;
            var engine      = new KestrelEngine(_libraryManager, _appShutdownService);

            engine.Start(1);
            foreach (var address in information.Addresses)
            {
                disposables.Add(engine.CreateServer(
                                    address.Scheme,
                                    address.Host,
                                    address.Port,
                                    async frame =>
                {
                    var request = new ServerRequest(frame);
                    await application.Invoke(request.Features);
                }));
            }
            disposables.Add(engine);
            return(new Disposable(() =>
            {
                foreach (var disposable in disposables)
                {
                    disposable.Dispose();
                }
            }));
        }
コード例 #6
0
        public ReplicationInfo(IServerInformation main)
            : base(main, Name)
        {
            if (main == null)
            {
                throw new ArgumentNullException(nameof(main));
            }

            Role = GetType <ReplicationRole>("role");
            if (Role == ReplicationRole.Slave)
            {
                LastSync               = GetType <long>("master_last_io_seconds_ago");
                MasterLinkStatus       = GetType <MasterLinkStatus>("master_link_status");
                SlaveReplOffset        = GetType <long>("slave_repl_offset");
                IsMasterSyncInProgress = GetType <byte>("master_sync_in_progress");
            }
            else if (Role == ReplicationRole.Master)
            {
                MasterReplOffset = GetType <long>("master_repl_offset");
                ConnectedSlaves  = GetType <int>("connected_slaves");
                if (ConnectedSlaves != null)
                {
                    Slaves = new SlaveInformation[ConnectedSlaves.Value];
                    for (int i = 0; i < ConnectedSlaves.Value; i++)
                    {
                        Slaves[i] = SlaveInformation.Parse(GetType($"slave{i}"));
                    }
                }
            }
        }
コード例 #7
0
 public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
 {
     var startInstance = new StartInstance(application);
     _startInstances.Add(startInstance);
     application(_featuresSupportedByThisHost);
     return startInstance;
 }
コード例 #8
0
        private RequestDelegate BuildApplication()
        {
            if (ServerFactory == null)
            {
                // Blow up if we don't have a server set at this point
                if (ServerFactoryLocation == null)
                {
                    throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()");
                }

                ServerFactory = _applicationServices.GetRequiredService <IServerLoader>().LoadServerFactory(ServerFactoryLocation);
            }

            _serverInstance = ServerFactory.Initialize(_config);
            var builderFactory = _applicationServices.GetRequiredService <IApplicationBuilderFactory>();
            var builder        = builderFactory.CreateBuilder(_serverInstance);

            builder.ApplicationServices = _applicationServices;

            var startupFilters = _applicationServices.GetService <IEnumerable <IStartupFilter> >();
            var configure      = Startup.ConfigureDelegate;

            foreach (var filter in startupFilters)
            {
                configure = filter.Configure(configure);
            }

            configure(builder);

            return(builder.Build());
        }
コード例 #9
0
        public ServerPacketProcessor(ServerBuilderOptions options,
                                     ILogger <ServerPacketProcessor> logger,
                                     IPacketHandlers packetHandlers,
                                     IServerInformation serverInformation,
                                     IPacketSerialiser packetSerialiser)
        {
            this.logger            = logger;
            this.packetHandlers    = packetHandlers;
            this.serverInformation = serverInformation;
            this.packetSerialiser  = packetSerialiser;

            tcpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections);

            for (var i = 0; i < tcpSenderObjectPool.Capacity; i++)
            {
                tcpSenderObjectPool.Push(new TcpSender(packetSerialiser));
            }

            udpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections * 2);

            for (var i = 0; i < udpSenderObjectPool.Capacity; i++)
            {
                udpSenderObjectPool.Push(new UdpSender(packetSerialiser));
            }
        }
コード例 #10
0
ファイル: HostingEngineTests.cs プロジェクト: yukozh/Hosting
        public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application)
        {
            var startInstance = new StartInstance(application);

            _startInstances.Add(startInstance);
            application(_featuresSupportedByThisHost);
            return(startInstance);
        }
コード例 #11
0
 public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
 {
     if (serverInformation.GetType() != typeof(StdioServerInformation))
     {
         throw new ArgumentException("wrong server", "serverInformation");
     }
     return new StdioServer(_input, _output, application);
 }
コード例 #12
0
 public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
 {
     var information = (NowinServerInformation)serverInformation;
     _callback = application;
     INowinServer server = information.Builder.Build();
     server.Start();
     return server;
 }
コード例 #13
0
ファイル: NowinServerFactory.cs プロジェクト: moljac/Ph4ct3x
 public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
 {
     var information = (NowinServerInformation)serverInformation;
     _callback = application;
     INowinServer server = information.Builder.Build();
     server.Start();
     return server;
 }
コード例 #14
0
 public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application)
 {
     if (serverInformation.GetType() != typeof(StdioServerInformation))
     {
         throw new ArgumentException("wrong server", "serverInformation");
     }
     return(new StdioServer(_input, _output, application));
 }
コード例 #15
0
        public Server(ServerBuilderOptions options,
                      ILogger logger,
                      IServiceProvider serviceProvider,
                      IPacketHandlers packetHandlers,
                      ITcpConnections tcpConnections,
                      IServerPacketProcessor serverPacketProcessor,
                      ITcpSocketListenerFactory tcpSocketListenerFactory,
                      IUdpSocketListenerFactory udpSocketListenerFactory,
                      IBufferManager bufferManager,
                      IServerInformation serverInformation,
                      IPacketSerialiser packetSerialiser)
        {
            this.tcpConnections    = tcpConnections;
            this.serverInformation = serverInformation;
            this.packetSerialiser  = packetSerialiser;
            bufferManager.InitBuffer();

            if (options.TcpPort > 0)
            {
                this.TcpListener = tcpSocketListenerFactory.Create();
            }

            if (options.UdpPort > 0)
            {
                this.UdpListener = udpSocketListenerFactory.Create();
            }

            Task.Factory.StartNew(() =>
            {
                while (this.serverInformation.IsRunning)
                {
                    if (this.eventArgs == null)
                    {
                        this.eventArgs = new ServerInformationEventArgs();
                    }

                    this.eventArgs.ProcessedTcpPackets =
                        serverInformation.ProcessedTcpPackets;
                    this.eventArgs.InvalidTcpPackets =
                        serverInformation.InvalidTcpPackets;
                    this.eventArgs.ProcessedUdpPackets =
                        serverInformation.ProcessedUdpPackets;
                    this.eventArgs.InvalidUdpPackets =
                        serverInformation.InvalidUdpPackets;
                    this.eventArgs.TcpConnections = tcpConnections.GetConnections()
                                                    .Count;

                    this.ServerInformationUpdated?.Invoke(this, this.eventArgs);

                    this.serverInformation.ProcessedTcpPackets = 0;
                    this.serverInformation.InvalidTcpPackets   = 0;
                    this.serverInformation.ProcessedUdpPackets = 0;
                    this.serverInformation.InvalidUdpPackets   = 0;

                    Thread.Sleep(10000);
                }
            });
        }
コード例 #16
0
 public DefaultUdpSocketListenerFactory(ServerBuilderOptions options,
                                        ILogger <UdpClientListener> logger,
                                        IServerPacketProcessor serverPacketProcessor,
                                        IServerInformation serverInformation)
 {
     this.options = options;
     this.logger  = logger;
     this.serverPacketProcessor = serverPacketProcessor;
     this.serverInformation     = serverInformation;
 }
コード例 #17
0
        protected BaseInformation(IServerInformation main, string category)
        {
            if (string.IsNullOrEmpty(category))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(category));
            }

            Main          = main ?? throw new ArgumentNullException(nameof(main));
            this.category = category;
        }
コード例 #18
0
ファイル: StatsInfo.cs プロジェクト: AndMu/Wikiled.Redis
        public StatsInfo(IServerInformation main)
            : base(main, Name)
        {
            if (main == null)
            {
                throw new System.ArgumentNullException(nameof(main));
            }

            TotalCommands = GetType <long>("total_commands_processed");
        }
コード例 #19
0
        public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application)
        {
            if (!(serverInformation.GetType() == typeof(ServerInformation)))
            {
                throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation");
            }

            _appDelegate = application;

            return(this);
        }
コード例 #20
0
        private static HostStatus[] GetSlaveInformation(IServerInformation information)
        {
            var slaves = new List <HostStatus>(information.Replication.Slaves.Length);

            foreach (var slaveInformation in information.Replication.Slaves)
            {
                slaves.Add(new HostStatus(slaveInformation.EndPoint, slaveInformation.Offset));
            }

            return(slaves.ToArray());
        }
コード例 #21
0
 public DefaultUdpSocketListenerFactory(ServerBuilderOptions options,
                                        ILogger logger,
                                        IServerPacketProcessor serverPacketProcessor,
                                        IBufferManager bufferManager,
                                        IServerInformation serverInformation)
 {
     this.options = options;
     this.logger  = logger;
     this.serverPacketProcessor = serverPacketProcessor;
     this.bufferManager         = bufferManager;
     this.serverInformation     = serverInformation;
 }
コード例 #22
0
        public PersistenceInfo(IServerInformation main)
            : base(main, Name)
        {
            if (main == null)
            {
                throw new ArgumentNullException(nameof(main));
            }

            AofSize        = GetType <long>("aof_current_size");
            IsRdbSaving    = GetType <byte>("rdb_bgsave_in_progress");
            IsAofRewriting = GetType <byte>("aof_rewrite_in_progress");
        }
コード例 #23
0
        public UdpClientListener(ServerBuilderOptions options,
                                 ILogger <UdpClientListener> logger,
                                 IServerPacketProcessor serverPacketProcessor,
                                 IServerInformation serverInformation)
        {
            this.options = options;
            this.logger  = logger;
            this.serverPacketProcessor = serverPacketProcessor;
            this.serverInformation     = serverInformation;

            endPointPool = new ObjectPool <EndPoint>(this.options.UdpSocketObjectPoolSize);

            for (var i = 0; i < endPointPool.Capacity; i++)
            {
                endPointPool.Push(new IPEndPoint(IPAddress.Loopback, this.options.UdpPort));
            }
        }
コード例 #24
0
        public IDisposable Start(IServerInformation serverInformation, Func <object, Task> application)
        {
            var _services = (IFireflyService)serverInformation;

            _services.Trace.Event(TraceEventType.Start, TraceMessage.ServerFactory);

            var endpoint = new IPEndPoint(IPAddress.Loopback, 3001);

            var listenSocket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.IP);

            listenSocket.Bind(endpoint);
            listenSocket.Listen(-1);

            WaitCallback connectionExecute = connection =>
            {
                _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryConnectionExecute);
                ((Connection)connection).Execute();
            };

            var    stop        = false;
            var    acceptEvent = new SocketAsyncEventArgs();
            Action accept      = () =>
            {
                while (!stop)
                {
                    _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptAsync);

                    if (listenSocket.AcceptAsync(acceptEvent))
                    {
                        return;
                    }

                    _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedSync);

                    if (acceptEvent.SocketError != SocketError.Success)
                    {
                        _services.Trace.Event(TraceEventType.Error, TraceMessage.ServerFactoryAcceptSocketError);
                    }

                    if (acceptEvent.SocketError == SocketError.Success &&
                        acceptEvent.AcceptSocket != null)
                    {
                        ThreadPool.QueueUserWorkItem(
                            connectionExecute,
                            new Connection(
                                _services,
                                application,
                                new SocketWrapper(acceptEvent.AcceptSocket),
                                OnDisconnect));
                    }
                    acceptEvent.AcceptSocket = null;
                }
            };

            acceptEvent.Completed += (_, __) =>
            {
                _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedAsync);

                if (acceptEvent.SocketError == SocketError.Success &&
                    acceptEvent.AcceptSocket != null)
                {
                    ThreadPool.QueueUserWorkItem(
                        connectionExecute,
                        new Connection(
                            _services,
                            application,
                            new SocketWrapper(acceptEvent.AcceptSocket),
                            OnDisconnect));
                }
                acceptEvent.AcceptSocket = null;
                accept();
            };
            accept();

            return(new Disposable(
                       () =>
            {
                _services.Trace.Event(TraceEventType.Stop, TraceMessage.ServerFactory);

                stop = true;
                listenSocket.Close();
                acceptEvent.Dispose();
            }));
        }
コード例 #25
0
 public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
 {
     return new StartInstance(application);
 }
コード例 #26
0
ファイル: MemoryInfo.cs プロジェクト: AndMu/Wikiled.Redis
 public MemoryInfo(IServerInformation main)
     : base(main, Memory)
 {
     UsedMemory          = GetType <long>("used_memory");
     MemoryFragmentation = GetType <double>("mem_fragmentation_ratio");
 }
コード例 #27
0
ファイル: TestServer.cs プロジェクト: humblelistener/Hosting
        public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
        {
            if (!(serverInformation.GetType() == typeof(ServerInformation)))
            {
                throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation");
            }

            _appDelegate = application;

            return this;
        }
コード例 #28
0
        private static SqlServerVersion GetTargetServerVersion(IServerInformation srv)
        {
            var version = srv.VersionMajor + srv.VersionMinor.ToString();
            if (version == "80")
                return SqlServerVersion.Version80;

            if (version == "90")
                return SqlServerVersion.Version90;

            if (version == "100")
                return SqlServerVersion.Version100;

            if (version == "1050")
                return SqlServerVersion.Version105;

            throw new Exception("Unsupported Server Version");
        }
コード例 #29
0
        public static IServiceCollection AddKafkaBusServer(this IServiceCollection services, IServerInformation information)
        {
            var serverFeatures = new KafkaBusFeatureCollection();

            serverFeatures.Set <IServerInformation>(information);
            serverFeatures.Set <IServerAddressesFeature>(information);
            services.AddSingleton(serverFeatures);
            services.AddTransient <Server>();
            return(services);
        }
コード例 #30
0
ファイル: HostingEngine.cs プロジェクト: Kagamine/Hosting
        private RequestDelegate BuildApplication()
        {
            if (ServerFactory == null)
            {
                // Blow up if we don't have a server set at this point
                if (ServerFactoryLocation == null)
                {
                    throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()");
                }

                ServerFactory = _applicationServices.GetRequiredService<IServerLoader>().LoadServerFactory(ServerFactoryLocation);
            }

            _serverInstance = ServerFactory.Initialize(_config);
            var builderFactory = _applicationServices.GetRequiredService<IApplicationBuilderFactory>();
            var builder = builderFactory.CreateBuilder(_serverInstance);
            builder.ApplicationServices = _applicationServices;

            var startupFilters = _applicationServices.GetService<IEnumerable<IStartupFilter>>();
            var configure = Startup.ConfigureDelegate;
            foreach (var filter in startupFilters)
            {
                configure = filter.Configure(configure);
            }

            configure(builder);

            return builder.Build();
        }
コード例 #31
0
 public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application)
 {
     return(new StartInstance(application));
 }
コード例 #32
0
        public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application)
        {
            var _services = (IFireflyService)serverInformation;
            _services.Trace.Event(TraceEventType.Start, TraceMessage.ServerFactory);

            var endpoint = new IPEndPoint(IPAddress.Loopback, 3001);

            var listenSocket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.IP);
            listenSocket.Bind(endpoint);
            listenSocket.Listen(-1);

            WaitCallback connectionExecute = connection =>
            {
                _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryConnectionExecute);
                ((Connection)connection).Execute();
            };

            var stop = false;
            var acceptEvent = new SocketAsyncEventArgs();
            Action accept = () =>
            {
                while (!stop)
                {
                    _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptAsync);

                    if (listenSocket.AcceptAsync(acceptEvent))
                    {
                        return;
                    }

                    _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedSync);

                    if (acceptEvent.SocketError != SocketError.Success)
                    {
                        _services.Trace.Event(TraceEventType.Error, TraceMessage.ServerFactoryAcceptSocketError);
                    }

                    if (acceptEvent.SocketError == SocketError.Success &&
                        acceptEvent.AcceptSocket != null)
                    {
                        ThreadPool.QueueUserWorkItem(
                            connectionExecute,
                            new Connection(
                                _services,
                                application,
                                new SocketWrapper(acceptEvent.AcceptSocket),
                                OnDisconnect));
                    }
                    acceptEvent.AcceptSocket = null;
                }
            };
            acceptEvent.Completed += (_, __) =>
            {
                _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedAsync);

                if (acceptEvent.SocketError == SocketError.Success &&
                    acceptEvent.AcceptSocket != null)
                {
                    ThreadPool.QueueUserWorkItem(
                        connectionExecute,
                        new Connection(
                            _services,
                            application,
                            new SocketWrapper(acceptEvent.AcceptSocket),
                            OnDisconnect));
                }
                acceptEvent.AcceptSocket = null;
                accept();
            };
            accept();

            return new Disposable(
                () =>
                {
                    _services.Trace.Event(TraceEventType.Stop, TraceMessage.ServerFactory);

                    stop = true;
                    listenSocket.Close();
                    acceptEvent.Dispose();
                });
        }