pub struct LlmpClient<SP> where
SP: ShMemProvider, {
pub sender: LlmpSender<SP>,
pub receiver: LlmpReceiver<SP>,
}
Expand description
Client side of LLMP
Fields
sender: LlmpSender<SP>
Outgoing channel to the broker
receiver: LlmpReceiver<SP>
Incoming (broker) broadcast map
Implementations
sourceimpl<SP> LlmpClient<SP> where
SP: ShMemProvider,
impl<SP> LlmpClient<SP> where
SP: ShMemProvider,
n
clients connect to a broker. They share an outgoing map with the broker,
and get incoming messages from the shared broker bus
sourcepub fn on_existing_shmem(
shmem_provider: SP,
_current_out_shmem: SP::ShMem,
_last_msg_sent_offset: Option<u64>,
current_broker_shmem: SP::ShMem,
last_msg_recvd_offset: Option<u64>
) -> Result<Self, Error>
pub fn on_existing_shmem(
shmem_provider: SP,
_current_out_shmem: SP::ShMem,
_last_msg_sent_offset: Option<u64>,
current_broker_shmem: SP::ShMem,
last_msg_recvd_offset: Option<u64>
) -> Result<Self, Error>
Reattach to a vacant client map.
It is essential, that the broker (or someone else) kept a pointer to the out_shmem
else reattach will get a new, empty page, from the OS, or fail
sourcepub fn on_existing_from_env(
shmem_provider: SP,
env_name: &str
) -> Result<Self, Error>
pub fn on_existing_from_env(
shmem_provider: SP,
env_name: &str
) -> Result<Self, Error>
Recreate this client from a previous [client.to_env()
]
sourcepub fn to_env(&self, env_name: &str) -> Result<(), Error>
pub fn to_env(&self, env_name: &str) -> Result<(), Error>
Write the current state to env.
A new client can attach to exactly the same state by calling LlmpClient::on_existing_shmem()
.
sourcepub fn describe(&self) -> Result<LlmpClientDescription, Error>
pub fn describe(&self) -> Result<LlmpClientDescription, Error>
Describe this client in a way that it can be recreated, for example after crash
sourcepub fn existing_client_from_description(
shmem_provider: SP,
description: &LlmpClientDescription
) -> Result<Self, Error>
pub fn existing_client_from_description(
shmem_provider: SP,
description: &LlmpClientDescription
) -> Result<Self, Error>
Create an existing client from description
sourcepub fn await_safe_to_unmap_blocking(&self)
pub fn await_safe_to_unmap_blocking(&self)
Waits for the sender to be save to unmap. If a receiver is involved on the other side, this function should always be called.
sourcepub fn safe_to_unmap(&self) -> bool
pub fn safe_to_unmap(&self) -> bool
If we are allowed to unmap this client
sourcepub unsafe fn mark_safe_to_unmap(&mut self)
pub unsafe fn mark_safe_to_unmap(&mut self)
For debug purposes: mark the client as save to unmap, even though it might not have been read.
Safety
This should only be called in a debug scenario. Calling this in other contexts may lead to a premature page unmap and result in a crash in another process, or an unexpected read from an empty page in a receiving process.
sourcepub fn new(
shmem_provider: SP,
initial_broker_shmem: LlmpSharedMap<SP::ShMem>,
sender_id: ClientId
) -> Result<Self, Error>
pub fn new(
shmem_provider: SP,
initial_broker_shmem: LlmpSharedMap<SP::ShMem>,
sender_id: ClientId
) -> Result<Self, Error>
Creates a new LlmpClient
sourcepub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>
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.
sourcepub fn send_buf_with_flags(
&mut self,
tag: Tag,
flags: Flags,
buf: &[u8]
) -> Result<(), Error>
pub fn send_buf_with_flags(
&mut self,
tag: Tag,
flags: Flags,
buf: &[u8]
) -> Result<(), Error>
Send a buf
with the given flags
.
sourcepub fn send_client_added_msg(
&mut self,
shm_str: &[u8; 20],
shm_id: usize
) -> Result<(), Error>
pub fn send_client_added_msg(
&mut self,
shm_str: &[u8; 20],
shm_id: usize
) -> Result<(), Error>
Informs the broker about a new client in town, with the given map id
sourcepub unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, Error>
pub unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, Error>
A client receives a broadcast message. Returns null if no message is availiable
Safety
Should be save, unless the internal state is corrupt. Returns raw ptr.
sourcepub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error>
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error>
A client blocks/spins until the next message gets posted to the page, then returns that message.
Safety
Should be save, unless the internal state is corrupt. Returns raw ptr.
sourcepub unsafe fn alloc_next(
&mut self,
buf_len: usize
) -> Result<*mut LlmpMsg, Error>
pub unsafe fn alloc_next(
&mut self,
buf_len: usize
) -> Result<*mut LlmpMsg, Error>
The current page could have changed in recv (EOP). Alloc the next message, internally handling end of page by allocating a new one.
Safety
Should be safe, but returns an unsafe ptr
sourcepub fn recv_buf(&mut self) -> Result<Option<(ClientId, Tag, &[u8])>, Error>
pub fn recv_buf(&mut self) -> Result<Option<(ClientId, Tag, &[u8])>, Error>
Returns the next message, tag, buf, if available, else None
sourcepub fn recv_buf_blocking(&mut self) -> Result<(ClientId, Tag, &[u8]), Error>
pub fn recv_buf_blocking(&mut self) -> Result<(ClientId, Tag, &[u8]), Error>
Receives a buf from the broker, looping until a message becomes available
sourcepub fn recv_buf_with_flags(
&mut self
) -> Result<Option<(ClientId, Tag, Flags, &[u8])>, Error>
pub fn recv_buf_with_flags(
&mut self
) -> Result<Option<(ClientId, Tag, Flags, &[u8])>, Error>
Receive a buf
from the broker, including the flags
used during transmission.
sourcepub fn create_using_env(shmem_provider: SP, env_var: &str) -> Result<Self, Error>
pub fn create_using_env(shmem_provider: SP, env_var: &str) -> Result<Self, Error>
Creates a new LlmpClient
, reading the map id and len from env
sourcepub fn create_attach_to_tcp(shmem_provider: SP, port: u16) -> Result<Self, Error>
pub fn create_attach_to_tcp(shmem_provider: SP, port: u16) -> Result<Self, Error>
Create a LlmpClient
, getting the ID from a given port
Trait Implementations
sourceimpl<SP: Debug> Debug for LlmpClient<SP> where
SP: ShMemProvider,
impl<SP: Debug> Debug for LlmpClient<SP> where
SP: ShMemProvider,
Auto Trait Implementations
impl<SP> RefUnwindSafe for LlmpClient<SP> where
SP: RefUnwindSafe,
<SP as ShMemProvider>::ShMem: RefUnwindSafe,
impl<SP> !Send for LlmpClient<SP>
impl<SP> !Sync for LlmpClient<SP>
impl<SP> Unpin for LlmpClient<SP> where
SP: Unpin,
<SP as ShMemProvider>::ShMem: Unpin,
impl<SP> UnwindSafe for LlmpClient<SP> where
SP: UnwindSafe,
<SP as ShMemProvider>::ShMem: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Tail, T> Prepend<T> for Tail
impl<Tail, T> Prepend<T> for Tail
type PreprendResult = Tail
type PreprendResult = Tail
The Resulting TupleList
, of an Prepend::prepend()
call,
including the prepended entry. Read more
sourcefn prepend(self, value: T) -> (T, <Tail as Prepend<T>>::PreprendResult)
fn prepend(self, value: T) -> (T, <Tail as Prepend<T>>::PreprendResult)
Prepend a value to this tuple, returning a new tuple with prepended value.