about
11/26/2022
RustComm With ThreadPool Repository
RustCommWithThreadPool Prototype Repository
Message-passing communicatior using TcpStream and TcpListener
Quick Status
Concept:
- Uses queued full-duplex buffered message sending and receiving
-
Each message has a fixed size header and
Vec<u8> body. -
For each
Connector<P, M, L> connection,Listener<P, L> processes messages until receiving a message with MessageType::END.Listener<P, L> spawns a thread for each client connection and processes messages inP::process_message . -
In this version,
P::process_message echos back message with "reply" appended as reply to sender. You observe that behavior by running test1, e.g.,cargo run --example test1 .
Current Design:
-
new() -> Message Create newMessage with empty body and MessageType::TEXT. -
set_type(&mut self, mt: u8) SetMessageType member to one of:TEXT, BYTES, END . -
get_type(&self) -> MessageType ReturnMessageType member value. -
set_body_bytes(&mut self, b: Vec<u8>) Setbody_buffer member to bytes fromb: Vec<u8> . -
set_body_str(&mut self, s: &str;) Setbody_buffer member to bytes froms: &str . -
get_body_size(&self) -> usize Return size in bytes of body member. -
get_body(&self) -> &Vec<u8> Returnbody_buffer member. -
get_body_str(&self) -> String Return body contents as lossyString . -
clear(&self) clear body contents.
Both Connector<P, M, L> and Listener<P, L> are parameterized with L ,
a type satisfying a Logger trait. The package defines two types that implement the trait,
VerboseLog and MuteLog that allow users to easily turn on and off event display
outputs. Fig 2. uses MuteLog in both Connector<P, M, L> and
Listener<P, L> .
-
new(addr: &'static str) -> std::io::Result<Connector<P,M,L>> Create newConnector<P,M,L> with running send and receive threads. -
is_connected(&self) -> bool is connected toaddr ?. -
post_message(&self, msg: M) Enqueues msg to send to connected Receiver. -
get_message(&mut self) -> M Reads reply message if available, else blocks. -
has_message(&self) -> bool Returns true if reply message is available.
-
new(nt: u8) -> Listener<P, L> Create newListener<P, L> with nt threads running. -
start(&mut self, addr: &'static str) -> std::io::Result<JoinHandle<()>> BindListener<P,L> toaddr and start listening on dedicated thread.
Operation:
Build:
Status:
- Add file transfer capability
-
Add user-defined Comm type that composes a
Connector andListener .