private void StartIPC() { Task.Run(async() => { // TODO: cleaner way? var nngFactory = new nng.Tests.TestFactory(); while (!m_hadPipe) { try { if (m_process == null) { return; } var pid = m_process.Id; // c# isnt f# or rust // why is this api trying to be both at once var pairResult = nngFactory .PairOpen() .ThenListen($"ipc:///tmp/fxs_instance_{pid}"); if (pairResult.TryError(out var error)) { await Task.Delay(500); continue; } m_pair = pairResult.Unwrap(); m_peer = new PipePeer(m_pair); m_peer.Start(); m_peer.CommandReceived += async cmd => { await HandleCommand(cmd); }; m_peer.TargetUnreachable += () => { m_pair = null; }; m_hadPipe = true; while (m_pair != null && m_process != null && pid == m_process.Id) { await Task.Delay(500); } m_peer.Stop(); } catch (Exception e) { Debug.WriteLine(e.ToString()); } } }); }
internal MonitorClient() { // TODO: cleaner way? var nngFactory = new nng.Tests.TestFactory(); var pairResult = nngFactory .PairOpen() .ThenDial($"ipc:///tmp/fxs_instance_{Process.GetCurrentProcess().Id}"); void TryQuit() { if (GetConvar("monitor_killServerOnBrokenPipe", "0") != "0") { Tick += async() => ExecuteCommand("quit \"Monitor pipe broken.\""); } } if (pairResult.IsErr()) { TryQuit(); return; } m_pair = pairResult.Ok(); m_peer = new PipePeer(m_pair); m_peer.CommandReceived += async cmd => { await HandleCommand(cmd); }; m_peer.TargetUnreachable += () => { TryQuit(); }; m_peer.Start(); Tick += MonitorClient_Tick; }