pub struct LlmpSender<SP>
where SP: ShMemProvider,
{ /* private fields */ }
Expand description

Sending end on a (unidirectional) sharedmap channel

Implementations§

source§

impl<SP> LlmpSender<SP>
where SP: ShMemProvider,

An actor on the sending part of the shared map

source

pub fn new( shmem_provider: SP, id: ClientId, keep_pages_forever: bool ) -> Result<Self, Error>

Create a new LlmpSender using a given ShMemProvider, and id. If keep_pages_forever is true, ShMem will never be freed. If it is false, the pages will be unmapped once they are full, and have been mapped by at least one LlmpReceiver.

source

pub fn id(&self) -> ClientId

ID of this sender.

source

pub unsafe fn reset(&mut self)

Completely reset the current sender map. Afterwards, no receiver should read from it at a different location. This is only useful if all connected llmp parties start over, for example after a crash.

Safety

Only safe if you really really restart the page on everything connected No receiver should read from this page at a different location.

source

pub fn on_existing_from_env( shmem_provider: SP, env_name: &str ) -> Result<Self, Error>

Reattach to a vacant out_shmem, to with a previous sender stored the information in an env before.

source

pub fn to_env(&self, env_name: &str) -> Result<(), Error>

Store the info to this sender to env. A new client can reattach to it using LlmpSender::on_existing_from_env().

source

pub fn await_safe_to_unmap_blocking(&self)

Waits for this sender to be save to unmap. If a receiver is involved, this function should always be called.

source

pub fn safe_to_unmap(&self) -> bool

If we are allowed to unmap this client

source

pub unsafe fn mark_safe_to_unmap(&mut self)

For debug purposes: Mark save to unmap, even though it might not have been read by a receiver yet.

Safety

If this method is called, the page may be unmapped before it is read by any receiver.

source

pub fn on_existing_shmem( shmem_provider: SP, current_out_shmem: SP::ShMem, last_msg_sent_offset: Option<u64> ) -> Result<Self, Error>

Reattach to a vacant out_shmem. It is essential, that the receiver (or someone else) keeps a pointer to this map else reattach will get a new, empty page, from the OS, or fail.

source

pub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error>

Allocates the next space on this sender page

source

pub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg)

Cancel send of the next message, this allows us to allocate a new message without sending this one.

Safety

They msg pointer may no longer be used after cancel_send

source

pub unsafe fn shrink_alloced( &mut self, msg: *mut LlmpMsg, shrinked_len: usize ) -> Result<(), Error>

Shrinks the allocated LlmpMsg to a given size.

Safety

The msg pointer will be dereferenced, if it’s not null.

source

pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>

Allocates a message of the given size, tags it, and sends it off.

source

pub fn send_buf_with_flags( &mut self, tag: Tag, flags: Flags, buf: &[u8] ) -> Result<(), Error>

Send a buf with the given flags.

source

pub fn describe(&self) -> Result<LlmpDescription, Error>

Describe this LlmpClient in a way that it can be restored later, using Self::on_existing_from_description.

source

pub fn on_existing_from_description( shmem_provider: SP, description: &LlmpDescription ) -> Result<Self, Error>

Create this client on an existing map from the given description. Acquired with [self.describe].

source

pub fn send_exiting(&mut self) -> Result<(), Error>

Send information that this client is exiting. The other side may free up all allocated memory. We are no longer allowed to send anything afterwards.

Examples found in repository?
examples/llmp_test/main.rs (line 205)
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
fn main() -> Result<(), Box<dyn std::error::Error>> {
    /* The main node has a broker, and a few worker threads */

    let mode = std::env::args()
        .nth(1)
        .expect("no mode specified, chose 'broker', 'b2b', 'ctr', 'adder', 'large', or 'exiting'");
    let port: u16 = std::env::args()
        .nth(2)
        .unwrap_or_else(|| "1337".into())
        .parse::<u16>()?;
    // in the b2b use-case, this is our "own" port, we connect to the "normal" broker node on startup.
    let b2b_port: u16 = std::env::args()
        .nth(3)
        .unwrap_or_else(|| "4242".into())
        .parse::<u16>()?;

    log::set_logger(&LOGGER).unwrap();
    log::set_max_level(log::LevelFilter::Trace);

    println!("Launching in mode {mode} on port {port}");

    match mode.as_str() {
        "broker" => {
            let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new()?)?;
            broker.launch_tcp_listener_on(port)?;
            // Exit when we got at least _n_ nodes, and all of them quit.
            broker.set_exit_cleanly_after(NonZeroUsize::new(1_usize).unwrap());
            broker.loop_with_timeouts(
                &mut broker_message_hook,
                BROKER_TIMEOUT,
                Some(SLEEP_BETWEEN_FORWARDS),
            );
        }
        "b2b" => {
            let mut broker = llmp::LlmpBroker::new(StdShMemProvider::new()?)?;
            broker.launch_tcp_listener_on(b2b_port)?;
            // connect back to the main broker.
            broker.connect_b2b(("127.0.0.1", port))?;
            broker.loop_with_timeouts(
                &mut broker_message_hook,
                BROKER_TIMEOUT,
                Some(SLEEP_BETWEEN_FORWARDS),
            );
        }
        "ctr" => {
            let mut client =
                llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
            let mut counter: u32 = 0;
            loop {
                counter = counter.wrapping_add(1);
                client.send_buf(_TAG_SIMPLE_U32_V1, &counter.to_le_bytes())?;
                println!("CTR Client writing {counter}");
                thread::sleep(Duration::from_secs(1));
            }
        }
        "adder" => {
            adder_loop(port)?;
        }
        "large" => {
            large_msg_loop(port)?;
        }
        "exiting" => {
            let mut client =
                llmp::LlmpClient::create_attach_to_tcp(StdShMemProvider::new()?, port)?;
            for i in 0..10_u32 {
                client.send_buf(_TAG_SIMPLE_U32_V1, &i.to_le_bytes())?;
                println!("Exiting Client writing {i}");
                thread::sleep(Duration::from_millis(10));
            }
            log::info!("Exiting Client exits");
            client.sender_mut().send_exiting()?;
        }
        _ => {
            println!("No valid mode supplied");
        }
    }
    Ok(())
}

Trait Implementations§

source§

impl<SP> Debug for LlmpSender<SP>
where SP: ShMemProvider + Debug, SP::ShMem: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<SP> RefUnwindSafe for LlmpSender<SP>

§

impl<SP> !Send for LlmpSender<SP>

§

impl<SP> !Sync for LlmpSender<SP>

§

impl<SP> Unpin for LlmpSender<SP>
where SP: Unpin, <SP as ShMemProvider>::ShMem: Unpin,

§

impl<SP> UnwindSafe for LlmpSender<SP>

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<Tail, T> Prepend<T> for Tail

§

type PreprendResult = Tail

The Resulting TupleList, of an Prepend::prepend() call, including the prepended entry.
source§

fn prepend(self, value: T) -> (T, <Tail as Prepend<T>>::PreprendResult)

Prepend a value to this tuple, returning a new tuple with prepended value.
source§

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

§

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>,

§

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.