pub struct LlmpBroker<SP> where
SP: ShMemProvider + 'static, {
pub llmp_out: LlmpSender<SP>,
pub llmp_clients: Vec<LlmpReceiver<SP>>,
/* private fields */
}
Expand description
The broker (node 0)
Fields
llmp_out: LlmpSender<SP>
Broadcast map from broker to all clients
llmp_clients: Vec<LlmpReceiver<SP>>
Users of Llmp can add message handlers in the broker. This allows us to intercept messages right in the broker. This keeps the out map clean.
Implementations
sourceimpl<SP> LlmpBroker<SP> where
SP: ShMemProvider + 'static,
impl<SP> LlmpBroker<SP> where
SP: ShMemProvider + 'static,
The broker forwards all messages to its own bus-like broadcast map. It may intercept messages passing through.
sourcepub fn new(shmem_provider: SP) -> Result<Self, Error>
pub fn new(shmem_provider: SP) -> Result<Self, Error>
Create and initialize a new LlmpBroker
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 new LlmpBroker
sttaching to a TCP port
sourcepub fn register_client(&mut self, client_page: LlmpSharedMap<SP::ShMem>)
pub fn register_client(&mut self, client_page: LlmpSharedMap<SP::ShMem>)
Registers a new client for the given sharedmap str and size.
Returns the id of the new client in [broker.client_shmem
]
sourcepub fn connect_b2b<A>(&mut self, addr: A) -> Result<(), Error> where
A: ToSocketAddrs,
pub fn connect_b2b<A>(&mut self, addr: A) -> Result<(), Error> where
A: ToSocketAddrs,
Connects to a broker running on another machine. This will spawn a new background thread, registered as client, that proxies all messages to a remote machine. Returns the description of the new page that still needs to be announced/added to the broker afterwards.
sourcepub fn once<F>(&mut self, on_new_msg: &mut F) -> Result<(), Error> where
F: FnMut(ClientId, Tag, Flags, &[u8]) -> Result<LlmpMsgHookResult, Error>,
pub fn once<F>(&mut self, on_new_msg: &mut F) -> Result<(), Error> where
F: FnMut(ClientId, Tag, Flags, &[u8]) -> Result<LlmpMsgHookResult, Error>,
The broker walks all pages and looks for changes, then broadcasts them on its own shared page, once.
sourcepub fn loop_forever<F>(
&mut self,
on_new_msg: &mut F,
sleep_time: Option<Duration>
) where
F: FnMut(ClientId, Tag, Flags, &[u8]) -> Result<LlmpMsgHookResult, Error>,
pub fn loop_forever<F>(
&mut self,
on_new_msg: &mut F,
sleep_time: Option<Duration>
) where
F: FnMut(ClientId, Tag, Flags, &[u8]) -> Result<LlmpMsgHookResult, Error>,
Loops infinitely, forwarding and handling all incoming messages from clients. Never returns. Panics on error. 5 millis of sleep can’t hurt to keep busywait not at 100%
sourcepub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>
pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error>
Broadcasts the given buf to all clients
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>
Sends a buf
with the given flags
.
sourcepub fn launch_tcp_listener_on(
&mut self,
port: u16
) -> Result<JoinHandle<()>, Error>
pub fn launch_tcp_listener_on(
&mut self,
port: u16
) -> Result<JoinHandle<()>, Error>
Launches a thread using a tcp listener socket, on which new clients may connect to this broker. Does so on the given port.
sourcepub fn launch_listener(
&mut self,
listener: Listener
) -> Result<JoinHandle<()>, Error>
pub fn launch_listener(
&mut self,
listener: Listener
) -> Result<JoinHandle<()>, Error>
Launches a thread using a listener socket, on which new clients may connect to this broker
Trait Implementations
sourceimpl<SP: Debug> Debug for LlmpBroker<SP> where
SP: ShMemProvider + 'static,
impl<SP: Debug> Debug for LlmpBroker<SP> where
SP: ShMemProvider + 'static,
Auto Trait Implementations
impl<SP> RefUnwindSafe for LlmpBroker<SP> where
SP: RefUnwindSafe,
<SP as ShMemProvider>::ShMem: RefUnwindSafe,
impl<SP> !Send for LlmpBroker<SP>
impl<SP> !Sync for LlmpBroker<SP>
impl<SP> Unpin for LlmpBroker<SP> where
SP: Unpin,
<SP as ShMemProvider>::ShMem: Unpin,
impl<SP> UnwindSafe for LlmpBroker<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.