pub struct SessionContext<'a> { /* private fields */ }Expand description
Everything a session may touch, for one call.
Implementations§
Source§impl SessionContext<'_>
impl SessionContext<'_>
Sourcepub fn info(&self) -> &ConnectionInfo
pub fn info(&self) -> &ConnectionInfo
The connection’s facts.
Sourcepub fn set_exchange_deadline(&mut self, at: Option<Instant>)
pub fn set_exchange_deadline(&mut self, at: Option<Instant>)
The deadline for the current exchange (None clears it).
Sourcepub fn set_idle_timeout(&mut self, timeout: Option<Duration>)
pub fn set_idle_timeout(&mut self, timeout: Option<Duration>)
Overrides this connection’s idle timeout from its next wait for an
exchange on; None restores the listener’s limit. For example, a
protocol shortens keep-alive while the worker pool is nearly full.
Values below the timer tick are raised to one tick.
use std::time::Duration;
use net_io::{Input, Session, SessionContext, Step};
struct KeepAlive;
impl Session for KeepAlive {
fn on_data(&mut self, cx: &mut SessionContext<'_>, input: &mut Input) -> Step {
let n = input.bytes().len();
input.consume(n);
let short = (cx.pressure() > 0.75).then_some(Duration::from_secs(2));
cx.set_idle_timeout(short);
Step::Write
}
}Sourcepub fn pressure(&self) -> f32
pub fn pressure(&self) -> f32
0.0 to 1.0: busy workers (blocking driver); 1.0 while the control line sheds.
Sourcepub fn kill_handle(&self) -> KillHandle
pub fn kill_handle(&self) -> KillHandle
A handle other threads can use to abort this connection.
Sourcepub fn buffers(&mut self) -> &mut BufferPool
pub fn buffers(&mut self) -> &mut BufferPool
This worker’s buffer pool.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for SessionContext<'a>
impl<'a> !Sync for SessionContext<'a>
impl<'a> !UnwindSafe for SessionContext<'a>
impl<'a> Freeze for SessionContext<'a>
impl<'a> Send for SessionContext<'a>
impl<'a> Unpin for SessionContext<'a>
impl<'a> UnsafeUnpin for SessionContext<'a>
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