Struct smoldot_light::platform::read_write::ReadWrite

source ·
pub struct ReadWrite<TNow> {
    pub now: TNow,
    pub incoming_buffer: Vec<u8>,
    pub expected_incoming_bytes: Option<usize>,
    pub read_bytes: usize,
    pub write_buffers: Vec<Vec<u8>>,
    pub write_bytes_queued: usize,
    pub write_bytes_queueable: Option<usize>,
    pub wake_up_after: Option<TNow>,
}

Fields§

§now: TNow§incoming_buffer: Vec<u8>

Buffer of socket data ready to be processed.

§expected_incoming_bytes: Option<usize>

Number of bytes that ReadWrite::incoming_buffer should contain. None if the remote has closed their reading side of the socket.

§read_bytes: usize

Total number of bytes that have been read from ReadWrite::incoming_buffer.

ReadWrite::incoming_buffer must have been advanced after these bytes.

§write_buffers: Vec<Vec<u8>>

List of buffers containing data to the written out. The consumer of the ReadWrite is expected to add buffers.

§write_bytes_queued: usize

Amount of data already queued, both outside and including ReadWrite::write_buffers.

§write_bytes_queueable: Option<usize>

Number of additional bytes that are allowed to be pushed to ReadWrite::write_buffers. None if the writing side of the stream is closed.

§wake_up_after: Option<TNow>

If Some, the socket must be waken up after the given TNow is reached.

Implementations§

source§

impl<TNow> ReadWrite<TNow>

source

pub fn is_dead(&self) -> bool

Returns true if the connection should be considered dead. That is, both ReadWrite::expected_incoming_bytes is None and ReadWrite::write_bytes_queueable is None.

source

pub fn close_write(&mut self)

Sets the writing side of the connection to closed.

This is simply a shortcut for setting ReadWrite::write_bytes_queueable to None.

source

pub fn incoming_buffer_available(&self) -> usize

Returns the size of the data available in the incoming buffer.

source

pub fn discard_all_incoming(&mut self)

Discards all the incoming data. Updates ReadWrite::read_bytes and decreases ReadWrite::expected_incoming_bytes by the number of consumed bytes.

source

pub fn incoming_bytes_take( &mut self, num: usize, ) -> Result<Option<Vec<u8>>, IncomingBytesTakeError>

Extract a certain number of bytes from the read buffer.

On success, updates ReadWrite::read_bytes and decreases ReadWrite::expected_incoming_bytes by the number of consumed bytes.

If not enough bytes are available, returns None and sets ReadWrite::expected_incoming_bytes to the requested number of bytes.

source

pub fn incoming_bytes_take_array<const N: usize>( &mut self, ) -> Result<Option<[u8; N]>, IncomingBytesTakeError>

Same as ReadWrite::incoming_bytes_take_array, but reads a number of bytes as a compile-time constant.

source

pub fn incoming_bytes_take_leb128( &mut self, max_decoded_number: usize, ) -> Result<Option<usize>, IncomingBytesTakeLeb128Error>

Extract an LEB128-encoded number from the start of the read buffer.

On success, updates ReadWrite::read_bytes and decreases ReadWrite::expected_incoming_bytes by the number of consumed bytes.

If not enough bytes are available, returns None and sets ReadWrite::expected_incoming_bytes to the required number of bytes.

Must be passed the maximum value that this function can return on success. An error is returned if the value sent by the remote is higher than this maximum. This parameter, while not strictly necessary, is here for safety, as it is easy to forget to check the value against a maximum.

source

pub fn write_from_vec(&mut self, data: &mut Vec<u8>)

Copies as much as possible from the content of data to ReadWrite::write_buffers and updates ReadWrite::write_bytes_queued and ReadWrite::write_bytes_queueable. The bytes that have been written are removed from data.

This function is recommended only if the Vec is small.

source

pub fn write_from_vec_deque(&mut self, data: &mut VecDeque<u8>)

Copies as much as possible from the content of data to ReadWrite::write_buffers and updates ReadWrite::write_bytes_queued and ReadWrite::write_bytes_queueable. The bytes that have been written are removed from data.

source

pub fn write_out(&mut self, data: Vec<u8>)

Adds the data to ReadWrite::write_buffers, increases ReadWrite::write_bytes_queued, and decreases ReadWrite::write_bytes_queueable.

§Panic

Panics if data.len() > write_bytes_queueable. Panics if the writing side is closed and data isn’t empty.

source

pub fn wake_up_after(&mut self, after: &TNow)
where TNow: Clone + Ord,

Sets ReadWrite::wake_up_after to min(wake_up_after, after).

source

pub fn wake_up_asap(&mut self)
where TNow: Clone,

Auto Trait Implementations§

§

impl<TNow> Freeze for ReadWrite<TNow>
where TNow: Freeze,

§

impl<TNow> RefUnwindSafe for ReadWrite<TNow>
where TNow: RefUnwindSafe,

§

impl<TNow> Send for ReadWrite<TNow>
where TNow: Send,

§

impl<TNow> Sync for ReadWrite<TNow>
where TNow: Sync,

§

impl<TNow> Unpin for ReadWrite<TNow>
where TNow: Unpin,

§

impl<TNow> UnwindSafe for ReadWrite<TNow>
where TNow: UnwindSafe,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more