Middleman
Middleman aims to make sending structures over a network easy. It is built on top of mio, and is in the same spirit as the library wire.
TCP
~~~~~~~~~
▲ ▼
▲ bytes ▼
▲ ▼
~~~~~~~~~
TCP
Middleman
┆ ┆
╵ ↓
Function
This library aims to provide a number of structs that implement the Middleman trait. At present, the only one available is Threadless, which leans on mio's non-blocking reads to support blocking and non-blocking sends and receives without requiring additional threads.
Using the library
- Implement
Messagefor any typesTyou want to send or receive. (This involves implementing theserdelibrary's serialization traits. In most cases theserde_derivemacros are just fine).
- Acquire your
mio::TcpStreamobject(s). See the documentation formiofor more information. - (optional) alter socketoptions as desired for your socket (eg: NoDelay).
- Wrap your stream with some
MiddleManimplmentor.
use ;
let mut mm = new;
That's it. Messages from your peer can be received using recv() (blocking) or try_recv() (non-blocking).
use ;
// blocking receive
let x1 = mm..unwrap;
// non-blocking receive
loop
Examples
See src/tests.rs for an example of a typical use case.