Exemplo n.º 1
0
        public Connection OnAccept(Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            if (Process == null || Process.HasExited)
            {
                if (TrySpawn())
                {
                    Logger.Write(LogLevel.Notice, "Started fastcgi daemon [dynamic] with pid {0} and config file {1}", Process.Id, Path.GetFileName(Name));
                    // Let the daemon start
                    Thread.Sleep(300);
                }
                else
                {
                    throw new Exception("Couldn't spawn child!");
                }
            }

            Socket onDemandSocket;

            FastCgi.Server.TryCreateUnixSocket(ConfigurationManager.OnDemandSock, out onDemandSocket);
            onDemandSocket.Connect();
            SocketPassing.SendTo(onDemandSocket.Handle, socket.Handle);
            Logger.Write(LogLevel.Debug, "Sent fd {0} via fd {1}", socket.Handle, onDemandSocket.Handle);
            onDemandSocket.Close();

            return(new Connection(socket));
        }
Exemplo n.º 2
0
        public Connection OnAccept(Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            Logger.Write(LogLevel.Debug, "ChildInfo.OnAccept");
            if (Process == null || Process.HasExited)
            {
                if (TrySpawn())
                {
                    var process = Process;
                    int id      = process.Id;
                    Logger.Write(LogLevel.Notice, "Started fastcgi daemon [dynamic] with pid {0} and config file {1}", id, Path.GetFileName(Name));
                    process.EnableRaisingEvents = true;
                    process.Exited += (sender, e) => Logger.Write(LogLevel.Notice, "Fastcgi daemon [dynamic] with pid {0} exited [it is {1}ly dead]", id, process.HasExited.ToString().ToLowerInvariant());
                    // Let the daemon start
                    Thread.Sleep(300);
                }
                else
                {
                    throw new Exception("Couldn't spawn child!");
                }
            }
            else
            {
                Logger.Write(LogLevel.Debug, "Recycling child with pid {0}", Process.Id);
            }

            Logger.Write(LogLevel.Debug, "Will connect to backend");
            var onDemandSocket = new UnixClient();

            Logger.Write(LogLevel.Debug, "Connecting to backend on {0}", OnDemandSock);
            if (OnDemandSock.StartsWith("\\0", StringComparison.Ordinal))
            {
                onDemandSocket.Connect('\0' + OnDemandSock.Substring(2));
            }
            else
            {
                Uri uri;
                if (Uri.TryCreate(OnDemandSock, UriKind.Absolute, out uri))
                {
                    onDemandSocket.Connect(uri.PathAndQuery);
                }
                else
                {
                    onDemandSocket.Connect(OnDemandSock);
                }
            }
            SocketPassing.SendTo(onDemandSocket.Client.Handle, socket.Handle);
            Logger.Write(LogLevel.Debug, "Sent fd {0} via fd {1}", socket.Handle, onDemandSocket.Client.Handle);
            onDemandSocket.Close();

            return(new Connection(socket));
        }
Exemplo n.º 3
0
        static void FpmTcpAccept(IAsyncResult res)
        {
            if (!res.IsCompleted)
            {
                throw new ArgumentException("res");
            }

            var socket = res.AsyncState as TcpListener;

            if (socket == null)
            {
                throw new ArgumentNullException("state");
            }

            using (var connection = socket.EndAcceptSocket(res)) {
                var back = new UnixClient(FASTCGI_SOCKET_PATH);
                SocketPassing.SendTo(back.Client, connection.Handle);
            }
        }
Exemplo n.º 4
0
        static void FastCgiAccept(IAsyncResult res)
        {
            if (!res.IsCompleted)
            {
                throw new ArgumentException("res");
            }

            var socket = res.AsyncState as Socket;

            if (socket == null)
            {
                throw new ArgumentNullException("state");
            }

            using (var connection = socket.EndAccept(res))
            {
                using (var stream = SocketPassing.ReceiveFrom(connection))
                    using (var writer = new StreamWriter(stream))
                        writer.WriteLine(MESSAGE);
            }
        }