From 5dfa03c2f6611cc7cb4d10b8d9c81c8c8fcd992c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugene=20=E2=80=9CAeron=E2=80=9D=20Glybin?= Date: Sun, 3 Mar 2024 03:27:04 +0100 Subject: [PATCH] Minor update Improves error handling. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 08c0852..634bb2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" + [[package]] name = "async-attributes" version = "1.1.2" @@ -327,6 +333,7 @@ dependencies = [ name = "decoyssh" version = "1.0.6" dependencies = [ + "anyhow", "async-signals", "async-std", "clap", diff --git a/Cargo.toml b/Cargo.toml index c305221..e449cc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ include = ["src/**/*", "LICENSE", "README.md"] edition = "2021" [dependencies] +anyhow = { version = "1.0.80" } async-std = { version = "1.12", features = ["attributes"] } async-signals = { version = "0.4" } clap = { version = "4.0", features = ["cargo", "derive", "env", "wrap_help"] } diff --git a/src/main.rs b/src/main.rs index 5e6229f..2321124 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod pool; use std::time::{Duration, Instant}; +use anyhow::{bail, Result}; use async_signals::Signals; use async_std::io::ErrorKind; use async_std::net::TcpListener; @@ -27,7 +28,7 @@ async fn process( pool: ConnectionPoolProxy, length: usize, delay: Duration, -) -> Result<(SocketAddr, Duration), std::io::Error> { +) -> Result<(SocketAddr, Duration)> { let addr = stream.peer_addr()?; let cap = length + CRLF.len(); let now = Instant::now(); @@ -56,6 +57,7 @@ async fn process( } } else { stream.shutdown(Shutdown::Both)?; + bail!("pool is not ready"); } pool.remove(addr).await;