mirror of
https://github.com/YGGverse/titanit.git
synced 2026-03-31 17:15:30 +00:00
handle errors
This commit is contained in:
parent
eff0b836f8
commit
f1f419481f
1 changed files with 18 additions and 13 deletions
31
src/main.rs
31
src/main.rs
|
|
@ -17,7 +17,6 @@ use std::{
|
|||
|
||||
fn main() -> Result<()> {
|
||||
use clap::Parser;
|
||||
|
||||
let argument = Arc::new(Argument::parse());
|
||||
|
||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#the-use-of-tls
|
||||
|
|
@ -135,20 +134,26 @@ fn gemini(
|
|||
) {
|
||||
Ok(()) => loop {
|
||||
let mut data = vec![0; argument.chunk];
|
||||
let l = item.file.read_at(&mut data, read as u64).unwrap();
|
||||
stream.write_all(&data[..l]).unwrap();
|
||||
read += l;
|
||||
// println!("[{}] [info] [{peer}] Chunk sent: {l} ({read} total)", now());
|
||||
// EOF
|
||||
if l == 0 {
|
||||
println!("[{}] [info] [{peer}] Response: {read} bytes", now());
|
||||
match close(stream) {
|
||||
match item.file.read_at(&mut data, read as u64) {
|
||||
Ok(l) => match stream.write_all(&data[..l]) {
|
||||
Ok(()) => {
|
||||
println!("[{}] [info] [{peer}] Connection closed by server.", now())
|
||||
// EOF
|
||||
if l == 0 {
|
||||
println!("[{}] [info] [{peer}] Response: {read} bytes", now());
|
||||
match close(stream) {
|
||||
Ok(()) => println!(
|
||||
"[{}] [info] [{peer}] Connection closed by server.",
|
||||
now()
|
||||
),
|
||||
Err(e) => println!("[{}] [warning] [{peer}] {e}", now()),
|
||||
}
|
||||
break;
|
||||
}
|
||||
read += l;
|
||||
}
|
||||
Err(e) => println!("[{}] [warning] [{peer}] {e}", now()),
|
||||
}
|
||||
break;
|
||||
Err(e) => println!("[{}] [error] [{peer}] {e}", now()),
|
||||
},
|
||||
Err(e) => println!("[{}] [error] [{peer}] {e}", now()),
|
||||
}
|
||||
},
|
||||
Err(e) => println!("[{}] [error] [{peer}] {e}", now()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue