Skip to content

Commit

Permalink
Don't panic on failed to send response
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Jan 29, 2025
1 parent ed7e6a9 commit 6e224b9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ async fn handle_stream(
upper.insert("DeviceList".into(), plist::Value::Array(device_list));
let res = RawPacket::new(upper, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!("Failed to send response to client: {e:}");
return;
}

continue;
}
Expand Down Expand Up @@ -400,7 +403,10 @@ async fn handle_stream(

let res = RawPacket::new(p, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!("Failed to send response to client: {e:?}");
return;
}

continue;
}
Expand All @@ -413,7 +419,10 @@ async fn handle_stream(

let res = RawPacket::new(p, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!("Failed to send response to client: {e:?}");
return;
}

continue;
}
Expand Down Expand Up @@ -470,7 +479,12 @@ async fn handle_stream(

let res = RawPacket::new(p, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!(
"Failed to send response to client: {e:?}"
);
return;
}

if let Err(e) = tokio::io::copy_bidirectional(
&mut stream,
Expand All @@ -490,7 +504,11 @@ async fn handle_stream(

let res = RawPacket::new(p, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!(
"Failed to send response to client: {e:?}"
);
}

continue;
}
Expand All @@ -507,7 +525,9 @@ async fn handle_stream(

let res = RawPacket::new(p, 1, 8, parsed.tag);
let res: Vec<u8> = res.into();
socket.write_all(&res).await.unwrap();
if let Err(e) = socket.write_all(&res).await {
warn!("Failed to send response to client: {e:?}");
}

continue;
}
Expand Down

0 comments on commit 6e224b9

Please sign in to comment.