mirror of
https://github.com/YGGverse/titanit.git
synced 2026-03-31 09:05:45 +00:00
update connection close handler
This commit is contained in:
parent
e20969c28d
commit
eb6c6afb12
1 changed files with 16 additions and 8 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -142,9 +142,12 @@ fn gemini(
|
|||
// EOF
|
||||
if l == 0 {
|
||||
println!("[{}] [info] [{peer}] Response: {read} bytes", now());
|
||||
stream.flush().unwrap();
|
||||
stream.shutdown().unwrap();
|
||||
println!("[{}] [info] [{peer}] Connection closed by server.", now());
|
||||
match close(stream) {
|
||||
Ok(()) => {
|
||||
println!("[{}] [info] [{peer}] Connection closed by server.", now())
|
||||
}
|
||||
Err(e) => println!("[{}] [warning] [{peer}] {e}", now()),
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
@ -158,7 +161,7 @@ fn gemini(
|
|||
.into_bytes(),
|
||||
stream,
|
||||
|result| match result {
|
||||
Ok(()) => println!("[{}] [error] [{peer}] {e}", now()),
|
||||
Ok(()) => println!("[{}] [warning] [{peer}] {e}", now()),
|
||||
Err(e) => println!("[{}] [error] [{peer}] {e}", now()),
|
||||
},
|
||||
),
|
||||
|
|
@ -383,13 +386,18 @@ fn titan(
|
|||
}
|
||||
}
|
||||
|
||||
fn close(stream: &mut TlsStream<TcpStream>) -> Result<()> {
|
||||
stream.flush()?;
|
||||
// close connection gracefully
|
||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#closing-connections
|
||||
stream.shutdown()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn send(data: &[u8], stream: &mut TlsStream<TcpStream>, callback: impl FnOnce(Result<()>)) {
|
||||
callback((|| {
|
||||
stream.write_all(data)?;
|
||||
stream.flush()?;
|
||||
// close connection gracefully
|
||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#closing-connections
|
||||
stream.shutdown()?;
|
||||
close(stream)?;
|
||||
Ok(())
|
||||
})());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue