pub struct ServerHandle { /* private fields */ }Expand description
A cloneable handle to a running server, safe to use from any thread.
let server = net_io::serve("127.0.0.1:7000", |conn| { conn.send_all(b"hi\n")?; Ok(()) })?;
let handle = server.handle();
std::thread::spawn(move || {
// ... wait for a signal from the application's signal library ...
handle.request_stop();
});
let report = server.wait_for_stop();
println!("drained: {} graceful, {} killed in {:?}", report.graceful, report.killed, report.took);Implementations§
Source§impl ServerHandle
impl ServerHandle
Sourcepub fn kill(&self, id: ConnectionId, reason: KillReason) -> bool
pub fn kill(&self, id: ConnectionId, reason: KillReason) -> bool
Aborts the connection id; false if it already closed or belongs to another server.
Sourcepub fn close_after_flush(
&self,
id: ConnectionId,
reason: KillReason,
within: Duration,
) -> bool
pub fn close_after_flush( &self, id: ConnectionId, reason: KillReason, within: Duration, ) -> bool
Closes the connection id after what it already queued goes out: its session
is given no more input, the output it queued is sent, then FIN and a linger
that reads and discards until the peer closes, all within within from when
its worker sees the request (on the reactor only what was queued then goes
out; on the blocking pool a write already in progress finishes). The close reason is
CloseReason::Killed(reason). A kill meanwhile (or a stop’s deadline) ends
it at once with a reset. false if it already closed, was already killed,
or belongs to another server.
For an ejector with a denial to deliver: kill resets the connection, and a
reset can destroy bytes the peer has not read yet (decision D-182).
use std::time::Duration;
let handle = server.handle();
handle.close_after_flush(id, net_io::KillReason(9), Duration::from_millis(100));Sourcepub fn close_door(&self)
pub fn close_door(&self)
Stops accepting.
Sourcepub fn request_stop(&self)
pub fn request_stop(&self)
Makes Server::wait_for_stop return after the drain. Does not block.