Removed panics
Replaced panics with errors, so from now on the server won't crash even if connection with one individual client would fail
This commit is contained in:
parent
b8d5fb0f0b
commit
9b6965933e
@ -61,7 +61,9 @@ pub async fn listen(
|
|||||||
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
||||||
let msg = String::from_utf8(vec_buf.clone())?;
|
let msg = String::from_utf8(vec_buf.clone())?;
|
||||||
if msg.trim() != "ACK" {
|
if msg.trim() != "ACK" {
|
||||||
panic!("ACK not received (buffersize), instead got {}", msg);
|
let e: Box<dyn std::error::Error + Send + Sync> =
|
||||||
|
format!("ACK not received (buffersize)").into();
|
||||||
|
return Err::<(), Box<dyn std::error::Error + Send + Sync>>(e);
|
||||||
} else {
|
} else {
|
||||||
vec_buf.clear();
|
vec_buf.clear();
|
||||||
}
|
}
|
||||||
@ -81,7 +83,9 @@ pub async fn listen(
|
|||||||
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
||||||
let msg = String::from_utf8(vec_buf.clone())?;
|
let msg = String::from_utf8(vec_buf.clone())?;
|
||||||
if msg.trim() != "FIN" {
|
if msg.trim() != "FIN" {
|
||||||
panic!("ACK not received (server-side-termination)");
|
let e: Box<dyn std::error::Error + Send + Sync> =
|
||||||
|
format!("ACK not received (server-side termination)").into();
|
||||||
|
return Err::<(), Box<dyn std::error::Error + Send + Sync>>(e);
|
||||||
} else {
|
} else {
|
||||||
// Empty error as error's reason is already logged with println
|
// Empty error as error's reason is already logged with println
|
||||||
let e: Box<dyn std::error::Error + Send + Sync> = "".into();
|
let e: Box<dyn std::error::Error + Send + Sync> = "".into();
|
||||||
@ -99,7 +103,9 @@ pub async fn listen(
|
|||||||
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
||||||
let msg = String::from_utf8(vec_buf.clone())?;
|
let msg = String::from_utf8(vec_buf.clone())?;
|
||||||
if msg.trim() != "ACK" {
|
if msg.trim() != "ACK" {
|
||||||
panic!("ACK not received (amount), instead got {}", msg);
|
let e: Box<dyn std::error::Error + Send + Sync> =
|
||||||
|
format!("ACK not received (file amount)").into();
|
||||||
|
return Err::<(), Box<dyn std::error::Error + Send + Sync>>(e);
|
||||||
} else {
|
} else {
|
||||||
vec_buf.clear();
|
vec_buf.clear();
|
||||||
}
|
}
|
||||||
@ -157,7 +163,9 @@ pub async fn listen(
|
|||||||
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
let _bytes_read = reader.read_until(b'\n', &mut vec_buf).await?;
|
||||||
let msg = String::from_utf8(vec_buf.clone())?;
|
let msg = String::from_utf8(vec_buf.clone())?;
|
||||||
if msg.trim() != "ACK" {
|
if msg.trim() != "ACK" {
|
||||||
panic!("ACK not received (file), instead got {}", msg);
|
let e: Box<dyn std::error::Error + Send + Sync> =
|
||||||
|
format!("ACK not received (single file's data)").into();
|
||||||
|
return Err::<(), Box<dyn std::error::Error + Send + Sync>>(e);
|
||||||
} else {
|
} else {
|
||||||
println!("[+] File transfer successfully done");
|
println!("[+] File transfer successfully done");
|
||||||
vec_buf.clear();
|
vec_buf.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user