about
11/25/2022
RustComm Repository
RustComm 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 in Fig. 2.
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() -> Listener<P, L> Create newListener<P, L> . -
start(&mut self, addr: &'static str) -> std::io::Result<JoinHandle<()>> BindListener<P,L> toaddr and start listening on dedicated thread.
Operation:
Build:
Status:
-
Define traitsMsg ,Sndr ,Rcvr , andProcess . Refactor package code intoConnector<C> andListener<P> , where C and P implement the traits. The intent is to allow designers to create application specific processing, providingListener s send and receive methods that are tailored to an application's messages and processing, that simply plug into the RustComm framework. -
Add reply messages to this demo. -
Add
Sender queueand a threadpool in Receiver - Add file transfer capability
-
Convert to buffered reads and writes - Add user-defined Comm type that composes a Sender and a Receiver.
- Support interchangeable Messages that use references to external facilities for defining message body contents rather than packing into message. Needed for file transfer so file blocks don't get copied into message and then, as part of message, get copied into stream. With that, we copy message header into stream followed by copy of file block into stream.