Struct ChannelExtcapControlReader

Source
pub struct ChannelExtcapControlReader {
    pub join_handle: JoinHandle<Result<(), ControlChannelError>>,
    pub read_channel: Receiver<ControlPacket<'static>>,
}
Expand description

A reader for an Extcap Control using a Channel. This is the easier to use, but higher overhead way to read control packets. When the reader is spawned, a thread is spawned to continuously read messages and writes them into a bounded channel. This allows reading the control messages without worrying about spawning async tasks, by calling try_read_packet every once in a while.

Assuming the extcap capture implementation uses a loop to read or generate the packets, it can repeatedly call try_read_packet to read and handle the control packets until there are no more buffered messages before starting the main capturing logic.

For example:

fn capture(reader: &ChannelExtcapControlReader) -> Result<()> {
    let pcap_header = ...;
    let mut pcap_writer = PcapWriter::with_header(fifo, pcap_header)?;
    loop {
        while let Some(packet) = reader.try_read_packet().await {
            // Handle the control packet
        }
        pcap_writer.write_packet(...)?;
    }
    Ok(())
}

Fields§

§join_handle: JoinHandle<Result<(), ControlChannelError>>

The join handle for the spawned thread. In most cases there is no need to use this, as the control fifo is expected to run for the whole duration of the capture.

§read_channel: Receiver<ControlPacket<'static>>

The channel to receive control packets from.

Implementations§

Source§

impl ChannelExtcapControlReader

Source

pub fn spawn(in_path: PathBuf) -> Self

Create a ChannelExtcapControlReader and spawns the underlying thread it uses to start reading the control packets from the pipe given in in_path.

Source

pub async fn try_read_packet(&mut self) -> Option<ControlPacket<'static>>

Try to read a buffered control packet, or return None if there are no incoming control packets.

Source

pub async fn read_packet(&mut self) -> Option<ControlPacket<'static>>

Reads a control packet. If the incoming channel is empty, this will block and wait until an incoming packet comes in. This is typically used when the extcap capture starts to wait for the Initialized packet from the control channel.

If you are only using this method and not using try_read_packet, consider whether you can use ExtcapControlReader directly for lower overhead.

Auto Trait Implementations§

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