コード例 #1
0
ファイル: SocketListener.cs プロジェクト: ststeiger/NancyHub
        /// <summary>
        /// Start this FastCgi application. Set <paramref name="background"/> to true to start this without blocking.
        /// </summary>
        public virtual void Start(bool background)
        {
            if (!SomeListenSocketHasBeenBound)
            {
                throw new InvalidOperationException("You have to bind to some address or unix socket file first");
            }

            if (tcpListenSocket != null && tcpListenSocket.IsBound)
            {
                tcpListenSocket.Listen(listenBacklog);
            }
            if (unixListenSocket != null && unixListenSocket.IsBound)
            {
                unixListenSocket.Listen(listenBacklog);
            }

            // Wait for connections without blocking
            IsRunning = true;

            if (Logger != null)
            {
                Logger.ServerStart();
            }

            if (background)
            {
                //TODO: If one of the tasks below is delayed (why in the world would that happen, idk) then this
                // method returns without being ready to accept connections..
                Task.Factory.StartNew(Work);
            }
            else
            {
                Work();
            }
        }