Struct middleman::Middleman [] [src]

pub struct Middleman { /* fields omitted */ }

Methods

impl Middleman
[src]

[src]

Create a new Middleman structure to wrap the given Mio TcpStream. The Middleman implements mio::Evented, but delegates its functions to this given stream As such, registering the Middleman and registering the TcpStream are anaologous.

[src]

Write the given message directly into the TcpStream. Returns Err variant if there is a problem serializing or writing the message. The call returns Ok(()) once the bytes are entirely written to the stream.

[src]

See send. This variant can be useful to avoid the overhead of repeatedly packing a message for whatever reason, eg: sending the same message using multiple Middleman structs.

Note that this function does NOT check for internal consistency of the packed message. So, if this message was constructed by a means other than Packed::new, then the results may be unpredictable.

[src]

Conume an iterator over some Message structs, sending them all in the order traversed (see send). Returns (a,b) where a gives the total number of messages sent successfully and where b is Ok if nothing goes wrong and an error otherwise. In the event of the first error, no more messages will be sent.

[src]

See send_all and send_packed. This uses the message iterator from the former and the packed messages from the latter.

[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.

NOTE: The correctness of this call depends on the sender sending an internally consistent PackedMessage. If you (or the sender) are manually manipulating the internal state of sent messages this may cause errors for the receiver. If you are sticking to the Middleman API and treating each PackedMessage as a black box, everything should be fine.

[src]

See recv. Will repeatedly call recv() until the next message is not yet ready. Recevied messages are placed into the buffer dest_vector. The return result is (a,b) where a is the total number of message successfully received and where b is OK(()) if all goes well and some Err otherwise. In the event of the first error, the call will return and not receive any further.

[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 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]

See recv_blocking. This function is intended as an alternative for use for cases where it is certain that this Middleman is the only registered mio::Evented for the provided Poll and Events objects. Thus, the call WILL NOT CHECK the token at all, presuming that all events are associated with this middleman.

[src]

Similar to recv_all_into, but rather than storing each received message 'm', the provided function is called with arguments (self, m) where self is &mut self. This allows for ergonomic utility of the received messages using a closure.

[src]

Combination of recv_all_map and recv_packed.

[src]

Similar to recv, except builds (instead of some M: Message), a PackedMessage object. These packed messages can be deserialized later, sent on the line without knowledge of the message type etc.

[src]

Similar to recv_packed, but the potentially-read bytes are not actually removed from the stream. The message will still be there.

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