mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-05 20:57:40 +01:00
Message-related functionality factored out into msg_t class.
This patch addresses serveral issues: 1. It gathers message related functionality scattered over whole codebase into a single class. 2. It makes zmq_msg_t an opaque datatype. Internals of the class don't pollute zmq.h header file. 3. zmq_msg_t size decreases from 48 to 32 bytes. That saves ~33% of memory in scenarios with large amount of small messages. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
28
src/lb.cpp
28
src/lb.cpp
@@ -18,12 +18,11 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../include/zmq.h"
|
||||
|
||||
#include "lb.hpp"
|
||||
#include "pipe.hpp"
|
||||
#include "err.hpp"
|
||||
#include "own.hpp"
|
||||
#include "msg.hpp"
|
||||
|
||||
zmq::lb_t::lb_t (own_t *sink_) :
|
||||
active (0),
|
||||
@@ -93,26 +92,26 @@ void zmq::lb_t::activated (writer_t *pipe_)
|
||||
active++;
|
||||
}
|
||||
|
||||
int zmq::lb_t::send (zmq_msg_t *msg_, int flags_)
|
||||
int zmq::lb_t::send (msg_t *msg_, int flags_)
|
||||
{
|
||||
// Drop the message if required. If we are at the end of the message
|
||||
// switch back to non-dropping mode.
|
||||
if (dropping) {
|
||||
|
||||
more = msg_->flags & ZMQ_MSG_MORE;
|
||||
more = msg_->flags () & msg_t::more;
|
||||
if (!more)
|
||||
dropping = false;
|
||||
|
||||
int rc = zmq_msg_close (msg_);
|
||||
int rc = msg_->close ();
|
||||
errno_assert (rc == 0);
|
||||
rc = zmq_msg_init (msg_);
|
||||
rc = msg_->init ();
|
||||
zmq_assert (rc == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (active > 0) {
|
||||
if (pipes [current]->write (msg_)) {
|
||||
more = msg_->flags & ZMQ_MSG_MORE;
|
||||
more = msg_->flags () & msg_t::more;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -138,8 +137,8 @@ int zmq::lb_t::send (zmq_msg_t *msg_, int flags_)
|
||||
}
|
||||
|
||||
// Detach the message from the data buffer.
|
||||
int rc = zmq_msg_init (msg_);
|
||||
zmq_assert (rc == 0);
|
||||
int rc = msg_->init ();
|
||||
errno_assert (rc == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -154,13 +153,16 @@ bool zmq::lb_t::has_out ()
|
||||
while (active > 0) {
|
||||
|
||||
// Check whether zero-sized message can be written to the pipe.
|
||||
zmq_msg_t msg;
|
||||
zmq_msg_init (&msg);
|
||||
msg_t msg;
|
||||
int rc = msg.init ();
|
||||
errno_assert (rc == 0);
|
||||
if (pipes [current]->check_write (&msg)) {
|
||||
zmq_msg_close (&msg);
|
||||
rc = msg.close ();
|
||||
errno_assert (rc == 0);
|
||||
return true;
|
||||
}
|
||||
zmq_msg_close (&msg);
|
||||
rc = msg.close ();
|
||||
errno_assert (rc == 0);
|
||||
|
||||
// Deactivate the pipe.
|
||||
active--;
|
||||
|
||||
Reference in New Issue
Block a user