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_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.
Trait Implementations§
Source§impl Clone for ServerHandle
impl Clone for ServerHandle
Auto Trait Implementations§
impl !RefUnwindSafe for ServerHandle
impl !UnwindSafe for ServerHandle
impl Freeze for ServerHandle
impl Send for ServerHandle
impl Sync for ServerHandle
impl Unpin for ServerHandle
impl UnsafeUnpin for ServerHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more