0.1.1: small tcp socket fixes

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2024-01-28 21:07:23 +03:00
parent c2d3ad0389
commit d32aceb82c
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C
3 changed files with 11 additions and 4 deletions

2
Cargo.lock generated
View file

@ -320,7 +320,7 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lonelyradio"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"chrono",
"clap",

View file

@ -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 <ivabus@ivabus.dev>" ]

View file

@ -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;