Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f0cc00c authored by Zach Johnson's avatar Zach Johnson
Browse files

GD: signal on signal port when server is ready

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --host
Change-Id: I24a2ef3349b53abacacbed117db6ca2da7dc6971
parent ce42f4a0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@ use futures::stream::StreamExt;

use bluetooth_with_facades::RootFacadeService;

use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr};
use std::sync::Arc;
use std::sync::Mutex;

use tokio::net::TcpStream;

use tokio::runtime::Runtime;

use nix::sys::signal;
@@ -67,10 +70,17 @@ async fn async_main(rt: Arc<Runtime>, mut sigint: mpsc::UnboundedReceiver<()>) {
        .build()
        .unwrap();

    indicate_started(signal_port).await;
    sigint.next().await;
    block_on(server.shutdown()).unwrap();
}

async fn indicate_started(signal_port: u16) {
    let address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), signal_port);
    let stream = TcpStream::connect(address).await.unwrap();
    stream.shutdown(Shutdown::Both).unwrap();
}

// TODO: remove as this is a temporary nix-based hack to catch SIGINT
fn install_sigint() -> mpsc::UnboundedReceiver<()> {
    let (tx, rx) = mpsc::unbounded();