Skip to main content

SessionContext

Struct SessionContext 

Source
pub struct SessionContext<'a> { /* private fields */ }
Expand description

Everything a session may touch, for one call.

Implementations§

Source§

impl SessionContext<'_>

Source

pub fn info(&self) -> &ConnectionInfo

The connection’s facts.

Source

pub fn output(&mut self) -> &mut Output

The output queue.

Source

pub fn now(&self) -> Instant

The worker’s clock.

Source

pub fn set_phase(&mut self, phase: Phase)

Chooses which deadlines run.

Source

pub fn set_exchange_deadline(&mut self, at: Option<Instant>)

The deadline for the current exchange (None clears it).

Source

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
    }
}
Source

pub fn draining(&self) -> bool

Whether drain started: finish the current exchange, then close.

Source

pub fn pressure(&self) -> f32

0.0 to 1.0: busy workers (blocking driver); 1.0 while the control line sheds.

Source

pub fn kill_handle(&self) -> KillHandle

A handle other threads can use to abort this connection.

Source

pub fn completer(&self) -> Completer

This worker’s completion queue.

Source

pub fn worker(&self) -> WorkerId

The worker that runs this connection.

Source

pub fn buffers(&mut self) -> &mut BufferPool

This worker’s buffer pool.

Source

pub fn release(&mut self, buffer: Buffer)

Returns a buffer (for example one taken by Input::swap); it is wiped.

Source

pub fn grow_input(&mut self, class: SizeClass) -> Result<(), NetError>

Moves the unconsumed input into a buffer of class after this call returns.

§Errors

Limit { which: ReadBuffer } above the maximum read class.

Trait Implementations§

Source§

impl Debug for SessionContext<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.