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)); }
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)); }
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); } }