Skip to main content

IpcReceiverSet

Struct IpcReceiverSet 

Source
pub struct IpcReceiverSet { /* private fields */ }
Expand description

Collection of IpcReceivers moved into the set; thus creating a common (and exclusive) endpoint for receiving messages on any of the added channels.

§Examples

let data = vec![0x52, 0x75, 0x73, 0x74, 0x00];
let (tx, rx) = ipc::channel().unwrap();
let mut rx_set = IpcReceiverSet::new().unwrap();

// Add the receiver to the receiver set and send the data
// from the sender
let rx_id = rx_set.add(rx).unwrap();
tx.send(data.clone()).unwrap();

// Poll the receiver set for any readable events
for event in rx_set.select().unwrap() {
    match event {
        IpcSelectionResult::MessageReceived(id, message) => {
            let rx_data: Vec<u8> = message.to().unwrap();
            assert_eq!(id, rx_id);
            assert_eq!(data, rx_data);
            println!("Received: {:?} from {}...", data, id);
        },
        IpcSelectionResult::ChannelClosed(id) => {
            assert_eq!(id, rx_id);
            println!("No more data from {}...", id);
        }
    }
}

Implementations§

Source§

impl IpcReceiverSet

Source

pub fn new() -> Result<IpcReceiverSet, Error>

Create a new empty IpcReceiverSet.

Receivers may then be added to the set with the add method.

Source

pub fn add<T>(&mut self, receiver: IpcReceiver<T>) -> Result<u64, Error>
where T: for<'de> Deserialize<'de> + Serialize,

Add and consume the IpcReceiver to the set of receivers to be polled. IpcReceiver: struct.IpcReceiver.html

Source

pub fn add_opaque(&mut self, receiver: OpaqueIpcReceiver) -> Result<u64, Error>

Add an OpaqueIpcReceiver to the set of receivers to be polled. OpaqueIpcReceiver: struct.OpaqueIpcReceiver.html

Source

pub fn select(&mut self) -> Result<Vec<IpcSelectionResult>, Error>

Wait for IPC messages received on any of the receivers in the set. The method will return multiple events. An event may be either a message received or a channel closed event.

Source

pub fn try_select(&mut self) -> Result<Vec<IpcSelectionResult>, TrySelectError>

Non-blocking attempt to receive IPC messages on any of the receivers in the set.

If at least one message is received and/or a disconnection of at least one of the receivers in the set occurs, these events are returned. An event is either a message received or a channel closed event.

If no messages are received and no disconnection of a receiver in the set occurs, TrySelectError::Empty is returned.

Source

pub fn try_select_timeout( &mut self, duration: Duration, ) -> Result<Vec<IpcSelectionResult>, TrySelectError>

Blocks for up to the specified duration attempting to receive IPC messages on any of the receivers in the set.

If, within the specified duration, at least one message is received and/or a disconnection of at least one of the receivers in the set occurs, these events are returned. An event is either a message received or a channel closed event.

If, within the specified duration, no message are received and no disconnection of a receiver in the set occurs, TrySelectError::Empty is returned.

This may block for longer than the specified duration if any of the IPC channels in the set are busy.

If the specified duration exceeds the duration that your operating system can represent in milliseconds, this may block forever. At the time of writing, the smallest duration that may trigger this behavior is over 24 days.

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.