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; }
// 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_); }
// Creates message from the supplied buffer. 0MQ takes care of // deallocating the buffer once it is not needed. The deallocation // function is supplied in ffn_ parameter. If ffn_ is NULL, no // deallocation happens - this is useful for sending static buffers. inline message_t (void *data_, size_t size_, free_fn *ffn_) { raw_message_init (this, data_, size_, ffn_); }
// 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_); }
// Creates message size_ bytes long. inline message_t (size_t size_) { raw_message_init (this, size_); }