Skip to content

Commit

Permalink
linkd: Developers, Developers, Dev...
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Simmerl <[email protected]>
  • Loading branch information
xla committed Sep 13, 2021
1 parent 3d4e38c commit a4ca29a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
2 changes: 2 additions & 0 deletions node-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ mod metrics;
pub mod node;
mod protocol;
mod signals;

#[cfg(unix)]
pub mod socket_activation;
25 changes: 11 additions & 14 deletions node-lib/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::panic;

use futures::future::{select_all, FutureExt as _};
use structopt::StructOpt as _;
use tokio::{net::UnixStream, spawn, sync::mpsc};
use tokio::{spawn, sync::mpsc};
use tracing::info;

use librad::{
Expand All @@ -22,7 +22,6 @@ use crate::{
metrics::graphite,
protocol,
signals,
socket_activation,
};

pub async fn run() -> anyhow::Result<()> {
Expand All @@ -44,13 +43,13 @@ pub async fn run() -> anyhow::Result<()> {
coalesced.push(graphite_task);
}

if let Some(_listener) = socket_activation::env()? {
// TODO(xla): Schedule listen loop.
} else {
// TODO(xla): Bind to configured/default socket path, constructed from
// profile info.
// TODO(xla): Schedule listen loop.
}
// if let Some(_listener) = socket_activation::env()? {
// TODO(xla): Schedule listen loop.
// } else {
// TODO(xla): Bind to configured/default socket path, constructed from
// profile info.
// TODO(xla): Schedule listen loop.
// }

// TODO(xla): Setup subroutines.
// - Public API
Expand All @@ -74,12 +73,10 @@ pub async fn run() -> anyhow::Result<()> {

#[cfg(unix)]
async fn cfg(args: &Args) -> anyhow::Result<Cfg<discovery::Static, BoxedSigner>> {
Ok(Cfg::from_args::<UnixStream>(args).await?)
Ok(Cfg::from_args::<tokio::net::UnixStream>(args).await?)
}

#[cfg(not(unix))]
#[cfg(windows)]
async fn cfg(args: &Args) -> anyhow::Result<Cfg<discovery::Static, BoxedSigner>> {
use tokio::net::TcpSocket;

Ok(Cfg::from_args::<TcpSocket>(args).await?)
Ok(Cfg::from_args::<tokio::net::TcpStream>(args).await?)
}
15 changes: 7 additions & 8 deletions node-lib/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> {
let mut term = signal(SignalKind::terminate())?;

let signal = select! {
_ = int.recv() => SignalKind::quit(),
_ = int.recv() => SignalKind::interrupt(),
_ = quit.recv() => SignalKind::quit(),
_ = term.recv() => SignalKind::terminate(),
};
Expand All @@ -27,20 +27,19 @@ pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> {
Ok(())
}

#[cfg(target_os = "windows")]
#[instrument(name = "signals subroutine", skip(signals, shutdown_tx))]
pub async fn routine(signals: Signals, shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> {
#[cfg(windows)]
#[instrument(name = "signals subroutine", skip(shutdown_tx))]
pub async fn routine(shutdown_tx: mpsc::Sender<()>) -> anyhow::Result<()> {
use tokio::signal::windows::*;

let mut br = ctrl_break()?;
let mut c = cltr_c()?;
let mut c = ctrl_c()?;

let signal = select! {
_ = br.recv() => SignalKind::quit(),
_ = c.recv() => SignalKind::quit(),
_ = br.recv() => info!("received Break signal"),
_ = c.recv() => info!("recieved CtrlC signal"),
};

info!(?signal, "received termination signal");
let _ = shutdown_tx.try_send(());

Ok(())
Expand Down

0 comments on commit a4ca29a

Please sign in to comment.