print duration in days if >24h

This commit is contained in:
soruh 2023-04-22 18:45:25 +02:00
parent c48d369854
commit fb1a2aa1c0
3 changed files with 13 additions and 11 deletions

View File

@ -277,7 +277,7 @@ async fn connect(
client.set_nodelay(true)?;
caller.set_nodelay(true)?;
let _ = timeout(CALL_TIMEOUT, tokio::io::copy_bidirectional(client, caller)).await;
_ = timeout(CALL_TIMEOUT, tokio::io::copy_bidirectional(client, caller)).await;
{
let mut port_handler = port_handler.lock().await;

View File

@ -266,7 +266,7 @@ async fn connection_handler(
};
let (_, mut writer) = stream.split();
let _ = packet.send(&mut writer).await;
_ = packet.send(&mut writer).await;
}
if let Some(port) = handler_metadata.port {
@ -293,7 +293,7 @@ async fn connection_handler(
}
sleep(Duration::from_secs(3)).await;
let _ = stream.shutdown().await;
_ = stream.shutdown().await;
}
fn main() -> eyre::Result<()> {

View File

@ -92,22 +92,24 @@ impl<T: Display> Debug for DisplayAsDebug<T> {
}
}
fn duration_in_hours(duration: Duration) -> String {
fn duration_string(duration: Duration) -> String {
let seconds_elapsed = duration.as_secs();
let hours = seconds_elapsed / (60 * 60);
let days = seconds_elapsed / (60 * 60 * 24);
let hours = seconds_elapsed / (60 * 60) % 24;
let minutes = (seconds_elapsed / 60) % 60;
let seconds = seconds_elapsed % 60;
match (hours > 0, minutes > 0) {
(true, _) => format!("{hours}h {minutes}min {seconds}s"),
(false, true) => format!("{minutes}min {seconds}s"),
match (days > 0, hours > 0, minutes > 0) {
(true, _, _) => format!("{days}d {hours}h {minutes}min {seconds}s"),
(false, true, _) => format!("{hours}h {minutes}min {seconds}s"),
(false, false, true) => format!("{minutes}min {seconds}s"),
_ => format!("{duration:.0?}"),
}
}
fn format_instant(instant: Instant) -> String {
let when = duration_in_hours(instant.elapsed()) + " ago";
let when = duration_string(instant.elapsed()) + " ago";
(|| -> eyre::Result<_> {
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)? - instant.elapsed();
@ -425,7 +427,7 @@ impl Rejector {
loop {
if let Ok((mut socket, _)) = listener.accept().await {
let (_, mut writer) = socket.split();
let _ = packet.send(&mut writer).await;
_ = packet.send(&mut writer).await;
}
}
})
@ -436,7 +438,7 @@ impl Rejector {
#[instrument(skip(self))]
async fn stop(self) -> (TcpListener, Packet) {
self.handle.abort();
let _ = self.handle.await;
_ = self.handle.await;
let (listener, packet) = Arc::try_unwrap(self.state).unwrap();
(listener.into_inner(), packet)
}