Struct middleman::Middleman [] [src]

pub struct Middleman { /* fields omitted */ }

Wraps a mio::TcpStream object. Implmenents mio::Evented so it can be registered for polling. Offers try_read and send functions primarily with variants for convenience. This structure doesn't involve any extra threading.

Note that data will only travel over the stream when read_in and write_out are called. Typically, these calls are agglutinated using the single call read_write in the context of a mio::Event. See the tests for some examples.

Methods

impl Middleman
[src]

[src]

Wraps the given mio::TcpStream in a new middleman.

[src]

This call is the bread and butter of reading and writing local changes to the middleman's internal state to the TcpStream within. If this function is never called, no progress will ever be made.

[src]

Force the middleman to try and write any waiting bytes to the TcpStream. Instead of blocking when the socket isn't ready, the call returns Ok(0). Errors in writing to the socket emerge as an Err(_) variant.

It is advised to rely on the read_write for reading and writing instead.

[src]

Force the middleman to try and read bytes from the inner TcpStream. Instead of blocking when the socket isn't ready, the call returns Ok(0). Errors in reading from the socket emerge as an Err(_) variant.

It is advised to rely on the read_write for reading and writing instead.

[src]

Serialize the given Message, and store it internally for writing to the socket later. This call will return Err(_) if serialization of the message fails, or the serialized representation is too large for the Middleman to represent (Structures are required to have a serialized representation no larger than std::u32::MAX).

Note that each send() call may serialize an entirely different type of structure. Be careful using this feature, as any receive calls on the other end expecting a different type may fail to read (at best) or erroniously produce valid (albeit undefined) data silently at worst.

[src]

Given some iterator over Message structs, sends them each in sequence. The return result is a tuple (a, b) where a gives the number of messages sent successfully, and b returns Err(_) with an error if something goes wrong.

After encountering the first error, the iteration will cease and the offending message will not be sent.

[src]

Attempt to read one message worth of bytes from the input buffer and discard it This operation doesn't require knowing the type of the struct. As such, this can be used to discard a message if somehow it is unserializable.

[src]

Attempt to dedserialize some data in the receiving buffer into a single complete structure with the given type M. If there is insufficient data at the moment, Ok(None) is returned.

As the type is provided by the reader, it is possible for the sent message to be misinterpreted as a different type. At best, this is detected by a failure in deserialization. If an error occurs, the data is not consumed from the Middleman. Subsequent reads will operate on the same data.

[src]

Keep attempting to call try_recv until the next message is no longer ready. Will push received messages into the provided destination buffer in the order received. See try_recv for more information.

Returns (a, b) where a is the number of messages successfully received and b is Err(_) if an error occurs attempting to deserialize a message. Upon the first error, no further messages nor the offending message are recieved or removed from the buffer. Subsequent recv() calls will thus operate on the same data that caused the error before.

[src]

Hijack the mio event loop, reading and writing to the socket as polling allows. Events not related to the recv() of this middleman (determined from the provided mio::Token) are pushed into the provided extra_events vector. Returns Ok(Some(_)) if a message was successfully received. May return Ok(None) if the user provides as timeout some non-none Duration. Returns Err(_) if something goes wrong with reading from the socket or deserializing the message. See try_recv for more information.

WARNING: The user should take care to iterate over these events also, as without them all the Evented objects registered with the provided poll object might experience lost wakeups. It is suggested that in the event of any recv_blocking calls in your loop, you extend the event loop with a drain() on the same vector passed here as extra_events (using the iterator chain function, for example.)

[src]

A convenience function similar to try_recv_all, but instead calls a provided function for each successfully received message instead of pushing them to a provided buffer. See try_recv_all and try_recv for moree information

[src]

Returns true if the internal buffer current holds 1+ messages, ready to be received. In this case, try_recv and similar functions are guaranteed to return a message.

[src]

Attempts to read a message from the internal buffer, just like try_recv, but instead makes no attempt to deserialize the struct data. Instead, bytes are appended to the provided byte buffer. For this reason, no type annotation is required.

[src]

Similar to try_recv, whether or not the call succeeds, the data is not removed from the internal buffer. Subsequent calls will thus repeatedely deserialize the same bytes.

Trait Implementations

impl Debug for Middleman
[src]

[src]

Formats the value using the given formatter. Read more

impl Evented for Middleman
[src]

[src]

Register self with the given Poll instance. Read more

[src]

Re-register self with the given Poll instance. Read more

[src]

Deregister self from the given Poll instance Read more

Auto Trait Implementations

impl Send for Middleman

impl Sync for Middleman