Example #1
0
bool zmq::mux_t::read (message_t *msg_)
{
    //  Underlying layers work with raw_message_t, layers above use message_t.
    //  Mux is the component that translates between the two.
    raw_message_t *msg = (raw_message_t*) msg_;

    //  Deallocate old content of the message.
    raw_message_destroy (msg);

    //  Round-robin over the pipes to get next message.
    for (int to_process = pipes.size (); to_process != 0; to_process --) {

        bool retrieved = pipes [current]->read ((raw_message_t*) msg_);

        current ++;
        if (current == pipes.size ())
            current = 0;

        if (retrieved)
            return true;
    }

    //  No message is available. Initialise the output parameter
    //  to be a 0-byte message.
    raw_message_init (msg, 0);
    return false;
}
Example #2
0
zmq::pipe_t::~pipe_t ()
{
    //  Purge the associated data dam.
    if (data_dam)
        delete data_dam;

    //  Destroy the messages in the pipe itself.
    raw_message_t message;
    pipe.flush ();
    while (pipe.read (&message))
        raw_message_destroy (&message);
}
Example #3
0
 //  Same as above, however, the message is rebuilt from the supplied
 //  buffer. See appropriate constructor for discussion of buffer
 //  deallocation mechanism.
 inline void rebuild (void *data_, size_t size_, free_fn *ffn_)
 {
     raw_message_destroy (this);
     raw_message_init (this, data_, size_, ffn_);            
 }
Example #4
0
 //  Destroys old content of the message and allocates buffer for the
 //  new message body. Having this as a separate function allows user
 //  to reuse once-allocated message for multiple times.
 inline void rebuild (size_t size_)
 {
     raw_message_destroy (this);
     raw_message_init (this, size_);            
 }
Example #5
0
 //  Destroys the message.
 inline ~message_t ()
 {
     raw_message_destroy (this);
 }