From d32aceb82c1cf65798344ef12933a4586ed1045c Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Sun, 28 Jan 2024 21:07:23 +0300 Subject: [PATCH] 0.1.1: small tcp socket fixes Signed-off-by: Ivan Bushchik --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b00e08e..a4b0066 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,7 +320,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "lonelyradio" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 50271f3..4391675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "lonelyradio" description = "TCP radio for singles" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MIT" authors = [ "Ivan Bushchik " ] diff --git a/src/main.rs b/src/main.rs index b3c311e..5749676 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,8 +106,15 @@ async fn stream(mut s: TcpStream) { ) .unwrap(); for sample in samples { - if s.write(&((sample * 32768_f32) as i16).to_le_bytes()).await.is_err() { - break 'track; + let result = s.write(&((sample * 32768_f32) as i16).to_le_bytes()).await; + if result.is_err() { + // Socket error -> stop + return; + } else { + if result.unwrap() == 0 { + // If socket cannot accept data -> stop + return; + } } } continue;