///////////////////////////////////////////////////////// static bool CheckHelper() { string storage_dir = PathFinder.GetRemoteStorageDir(false); if (storage_dir == null) { return(false); } // FIXME: We shouldn't need to know the path to the helper socket. string socket_name = Path.Combine(storage_dir, "socket-helper"); if (!File.Exists(socket_name)) { return(false); } // Open, and then immediately close, a connection to the helper's socket. try { UnixClient test_client; test_client = new UnixClient(socket_name); test_client.Close(); return(true); } catch (Exception ex) { return(false); } }
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)); }
public override void Close() { bool previously_closed = this.IsClosed; // Important to set this before we close the // UnixClient, since that will trigger the // ReadCallback() method, reading 0 bytes off the // wire, and we check this.closed in there. this.IsClosed = true; if (client != null) { client.Close(); client = null; } if (!previously_closed) { InvokeClosedEvent(); } }