pub struct KillHandle { /* private fields */ }Expand description
Closes one connection abortively from any thread.
The owning thread does the close; the killer only sets a flag and wakes it, so it can never close a reused descriptor number.
§Examples
use net_io::KillReason;
let mut conn = net_io::connect("127.0.0.1:7000")?;
let kill = conn.kill_handle();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_secs(1));
kill.kill(KillReason(1));
});
let mut buf = [0u8; 16];
assert!(matches!(conn.recv(&mut buf), Err(net_io::NetError::Killed { .. })));Implementations§
Source§impl KillHandle
impl KillHandle
Sourcepub fn kill(&self, reason: KillReason) -> bool
pub fn kill(&self, reason: KillReason) -> bool
Kills the connection; false if it already closed (or was already killed).
Sourcepub fn id(&self) -> ConnectionId
pub fn id(&self) -> ConnectionId
The connection’s id.
Trait Implementations§
Source§impl Clone for KillHandle
impl Clone for KillHandle
Auto Trait Implementations§
impl Freeze for KillHandle
impl RefUnwindSafe for KillHandle
impl Send for KillHandle
impl Sync for KillHandle
impl Unpin for KillHandle
impl UnsafeUnpin for KillHandle
impl UnwindSafe for KillHandle
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