OSDN Git Service

GD: signal on signal port when server is ready
authorZach Johnson <zachoverflow@google.com>
Tue, 3 Nov 2020 19:11:26 +0000 (11:11 -0800)
committerZach Johnson <zachoverflow@google.com>
Fri, 6 Nov 2020 21:10:24 +0000 (13:10 -0800)
Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --host
Change-Id: I24a2ef3349b53abacacbed117db6ca2da7dc6971

gd/rust/facade/src/main.rs

index 7653975..3af3d3f 100644 (file)
@@ -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();