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