2009-08-27 10:54:28 +02:00
|
|
|
/*
|
2010-01-05 08:29:35 +01:00
|
|
|
Copyright (c) 2007-2010 iMatix Corporation
|
2009-08-27 10:54:28 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2009-08-27 10:54:28 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2009-08-27 10:54:28 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-08-27 10:54:28 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
#include <new>
|
|
|
|
|
2010-03-11 20:33:27 +01:00
|
|
|
#include "../include/zmq.h"
|
2009-08-28 16:51:46 +02:00
|
|
|
|
2009-08-27 10:54:28 +02:00
|
|
|
#include "pipe.hpp"
|
2010-08-06 17:49:37 +02:00
|
|
|
#include "likely.hpp"
|
2009-08-27 10:54:28 +02:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq::reader_t::reader_t (object_t *parent_, pipe_t *pipe_,
|
|
|
|
uint64_t lwm_) :
|
2009-08-27 10:54:28 +02:00
|
|
|
object_t (parent_),
|
2010-08-28 13:06:58 +02:00
|
|
|
active (true),
|
2010-08-06 17:49:37 +02:00
|
|
|
pipe (pipe_),
|
|
|
|
writer (NULL),
|
2009-08-27 10:54:28 +02:00
|
|
|
lwm (lwm_),
|
2010-03-01 10:13:26 +01:00
|
|
|
msgs_read (0),
|
2010-08-06 17:49:37 +02:00
|
|
|
sink (NULL),
|
|
|
|
terminating (false)
|
|
|
|
{
|
|
|
|
// Note that writer is not set here. Writer will inform reader about its
|
|
|
|
// address once it is created (via set_writer method).
|
|
|
|
}
|
|
|
|
|
|
|
|
void zmq::reader_t::set_writer (writer_t *writer_)
|
|
|
|
{
|
|
|
|
zmq_assert (!writer);
|
|
|
|
writer = writer_;
|
|
|
|
}
|
2009-08-27 10:54:28 +02:00
|
|
|
|
|
|
|
zmq::reader_t::~reader_t ()
|
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// Pipe as such is owned and deallocated by reader object.
|
|
|
|
// The point is that reader processes the last step of terminal
|
|
|
|
// handshaking (term_ack).
|
|
|
|
zmq_assert (pipe);
|
|
|
|
|
|
|
|
// First delete all the unread messages in the pipe. We have to do it by
|
|
|
|
// hand because zmq_msg_t is a POD, not a class, so there's no associated
|
|
|
|
// destructor.
|
|
|
|
zmq_msg_t msg;
|
|
|
|
while (pipe->read (&msg))
|
|
|
|
zmq_msg_close (&msg);
|
|
|
|
|
|
|
|
delete pipe;
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
void zmq::reader_t::set_event_sink (i_reader_events *sink_)
|
2009-12-01 14:58:00 +01:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq_assert (!sink);
|
|
|
|
sink = sink_;
|
2009-12-01 14:58:00 +01:00
|
|
|
}
|
|
|
|
|
2010-07-14 18:31:17 +02:00
|
|
|
bool zmq::reader_t::is_delimiter (zmq_msg_t &msg_)
|
|
|
|
{
|
|
|
|
unsigned char *offset = 0;
|
|
|
|
|
|
|
|
return msg_.content == (void*) (offset + ZMQ_DELIMITER);
|
|
|
|
}
|
|
|
|
|
2009-09-30 10:08:35 +02:00
|
|
|
bool zmq::reader_t::check_read ()
|
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
if (!active)
|
2010-08-06 17:49:37 +02:00
|
|
|
return false;
|
|
|
|
|
2009-09-30 10:08:35 +02:00
|
|
|
// Check if there's an item in the pipe.
|
2010-08-28 13:06:58 +02:00
|
|
|
if (!pipe->check_read ()) {
|
|
|
|
active = false;
|
2010-07-14 18:31:17 +02:00
|
|
|
return false;
|
2010-08-28 13:06:58 +02:00
|
|
|
}
|
2010-07-14 18:31:17 +02:00
|
|
|
|
|
|
|
// If the next item in the pipe is message delimiter,
|
|
|
|
// initiate its termination.
|
|
|
|
if (pipe->probe (is_delimiter)) {
|
2010-10-08 17:23:21 +02:00
|
|
|
zmq_msg_t msg;
|
|
|
|
bool ok = pipe->read (&msg);
|
|
|
|
zmq_assert (ok);
|
|
|
|
if (sink)
|
|
|
|
sink->delimited (this);
|
2010-08-06 17:49:37 +02:00
|
|
|
terminate ();
|
2010-07-14 18:31:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-09-30 10:08:35 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:54:28 +02:00
|
|
|
bool zmq::reader_t::read (zmq_msg_t *msg_)
|
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
if (!active)
|
2010-08-06 17:49:37 +02:00
|
|
|
return false;
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
if (!pipe->read (msg_)) {
|
|
|
|
active = false;
|
2009-08-28 16:51:46 +02:00
|
|
|
return false;
|
2010-08-28 13:06:58 +02:00
|
|
|
}
|
2009-08-28 16:51:46 +02:00
|
|
|
|
|
|
|
// If delimiter was read, start termination process of the pipe.
|
|
|
|
unsigned char *offset = 0;
|
|
|
|
if (msg_->content == (void*) (offset + ZMQ_DELIMITER)) {
|
2010-10-08 17:23:21 +02:00
|
|
|
if (sink)
|
|
|
|
sink->delimited (this);
|
2010-08-06 17:49:37 +02:00
|
|
|
terminate ();
|
2009-08-28 16:51:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-08-27 10:54:28 +02:00
|
|
|
|
2010-03-27 21:25:40 +01:00
|
|
|
if (!(msg_->flags & ZMQ_MSG_MORE))
|
2010-03-27 09:24:38 +01:00
|
|
|
msgs_read++;
|
|
|
|
|
2010-03-01 10:13:26 +01:00
|
|
|
if (lwm > 0 && msgs_read % lwm == 0)
|
2010-08-28 10:15:03 +02:00
|
|
|
send_activate_writer (writer, msgs_read);
|
2009-08-28 16:51:46 +02:00
|
|
|
|
|
|
|
return true;
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
void zmq::reader_t::terminate ()
|
2009-08-27 10:54:28 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// If termination was already started by the peer, do nothing.
|
|
|
|
if (terminating)
|
|
|
|
return;
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
active = false;
|
2010-08-06 17:49:37 +02:00
|
|
|
terminating = true;
|
|
|
|
send_pipe_term (writer);
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-28 10:15:03 +02:00
|
|
|
void zmq::reader_t::process_activate_reader ()
|
2009-08-27 10:54:28 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// Forward the event to the sink (either socket or session).
|
2010-08-28 13:06:58 +02:00
|
|
|
active = true;
|
2010-08-06 17:49:37 +02:00
|
|
|
sink->activated (this);
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2009-08-28 16:51:46 +02:00
|
|
|
void zmq::reader_t::process_pipe_term_ack ()
|
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// At this point writer may already be deallocated.
|
|
|
|
// For safety's sake drop the reference to it.
|
|
|
|
writer = NULL;
|
|
|
|
|
|
|
|
// Notify owner about the termination.
|
|
|
|
zmq_assert (sink);
|
|
|
|
sink->terminated (this);
|
|
|
|
|
|
|
|
// Deallocate resources.
|
|
|
|
delete this;
|
2009-08-28 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq::writer_t::writer_t (object_t *parent_, pipe_t *pipe_, reader_t *reader_,
|
2010-06-21 15:06:51 +02:00
|
|
|
uint64_t hwm_, int64_t swap_size_) :
|
2009-08-27 10:54:28 +02:00
|
|
|
object_t (parent_),
|
2010-08-28 13:06:58 +02:00
|
|
|
active (true),
|
2010-08-06 17:49:37 +02:00
|
|
|
pipe (pipe_),
|
|
|
|
reader (reader_),
|
2009-08-27 10:54:28 +02:00
|
|
|
hwm (hwm_),
|
2010-03-01 10:13:26 +01:00
|
|
|
msgs_read (0),
|
|
|
|
msgs_written (0),
|
2010-08-28 13:06:58 +02:00
|
|
|
swap (NULL),
|
2010-08-06 17:49:37 +02:00
|
|
|
sink (NULL),
|
2010-08-28 13:06:58 +02:00
|
|
|
swapping (false),
|
|
|
|
pending_delimiter (false),
|
|
|
|
terminating (false)
|
2009-08-28 16:51:46 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// Inform reader about the writer.
|
|
|
|
reader->set_writer (this);
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
// Open the swap file, if required.
|
2010-06-21 15:06:51 +02:00
|
|
|
if (swap_size_ > 0) {
|
2010-08-28 13:14:45 +02:00
|
|
|
swap = new (std::nothrow) swap_t (swap_size_);
|
2010-08-28 13:06:58 +02:00
|
|
|
zmq_assert (swap);
|
|
|
|
int rc = swap->init ();
|
|
|
|
zmq_assert (rc == 0);
|
2010-06-21 15:06:51 +02:00
|
|
|
}
|
2009-08-28 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:54:28 +02:00
|
|
|
zmq::writer_t::~writer_t ()
|
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
if (swap)
|
|
|
|
delete swap;
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
void zmq::writer_t::set_event_sink (i_writer_events *sink_)
|
2009-12-01 14:58:00 +01:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq_assert (!sink);
|
|
|
|
sink = sink_;
|
2009-12-01 14:58:00 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:13:26 +01:00
|
|
|
bool zmq::writer_t::check_write ()
|
2009-08-27 10:54:28 +02:00
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
// We've already checked and there's no space free for the new message.
|
|
|
|
// There's no point in checking once again.
|
|
|
|
if (unlikely (!active))
|
2010-03-01 10:13:26 +01:00
|
|
|
return false;
|
2010-08-28 13:06:58 +02:00
|
|
|
|
|
|
|
if (unlikely (swapping)) {
|
|
|
|
if (unlikely (swap->full ())) {
|
|
|
|
active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (unlikely (pipe_full ())) {
|
|
|
|
if (swap)
|
|
|
|
swapping = true;
|
|
|
|
else {
|
|
|
|
active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-01 10:13:26 +01:00
|
|
|
}
|
2009-08-27 10:54:28 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-23 10:22:54 +02:00
|
|
|
bool zmq::writer_t::write (zmq_msg_t *msg_)
|
2009-08-27 10:54:28 +02:00
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
if (unlikely (!check_write ()))
|
2010-03-01 10:13:26 +01:00
|
|
|
return false;
|
2010-06-21 15:06:51 +02:00
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
if (unlikely (swapping)) {
|
|
|
|
bool stored = swap->store (msg_);
|
|
|
|
zmq_assert (stored);
|
2010-06-21 15:06:51 +02:00
|
|
|
if (!(msg_->flags & ZMQ_MSG_MORE))
|
2010-08-28 13:06:58 +02:00
|
|
|
swap->commit ();
|
|
|
|
return true;
|
2010-03-01 10:13:26 +01:00
|
|
|
}
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
pipe->write (*msg_, msg_->flags & ZMQ_MSG_MORE);
|
|
|
|
if (!(msg_->flags & ZMQ_MSG_MORE))
|
|
|
|
msgs_written++;
|
|
|
|
|
2009-08-27 10:54:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-09 08:43:20 +01:00
|
|
|
void zmq::writer_t::rollback ()
|
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
// Remove incomplete message from the swap.
|
|
|
|
if (unlikely (swapping)) {
|
|
|
|
swap->rollback ();
|
|
|
|
return;
|
2010-06-21 15:06:51 +02:00
|
|
|
}
|
2010-03-01 10:13:26 +01:00
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
// Remove incomplete message from the pipe.
|
2010-06-21 15:06:51 +02:00
|
|
|
zmq_msg_t msg;
|
2010-03-01 10:13:26 +01:00
|
|
|
while (pipe->unwrite (&msg)) {
|
2010-05-19 06:31:57 +02:00
|
|
|
zmq_assert (msg.flags & ZMQ_MSG_MORE);
|
2010-03-09 08:43:20 +01:00
|
|
|
zmq_msg_close (&msg);
|
2010-03-01 10:13:26 +01:00
|
|
|
}
|
2010-03-09 08:43:20 +01:00
|
|
|
}
|
|
|
|
|
2009-08-27 10:54:28 +02:00
|
|
|
void zmq::writer_t::flush ()
|
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
// In the swapping mode, flushing is automatically handled by swap object.
|
|
|
|
if (!swapping && !pipe->flush ())
|
2010-08-28 10:15:03 +02:00
|
|
|
send_activate_reader (reader);
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
void zmq::writer_t::terminate ()
|
2009-08-28 16:51:46 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// Prevent double termination.
|
|
|
|
if (terminating)
|
|
|
|
return;
|
2009-08-28 16:51:46 +02:00
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
// Mark the pipe as not available for writing.
|
|
|
|
active = false;
|
2010-06-21 15:06:51 +02:00
|
|
|
|
2010-08-07 09:52:34 +02:00
|
|
|
// Rollback any unfinished messages.
|
|
|
|
rollback ();
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
if (swapping) {
|
|
|
|
pending_delimiter = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push delimiter into the pipe. Trick the compiler to belive that
|
|
|
|
// the tag is a valid pointer. Note that watermarks are not checked
|
|
|
|
// thus the delimiter can be written even though the pipe is full.
|
2009-08-28 16:51:46 +02:00
|
|
|
zmq_msg_t msg;
|
|
|
|
const unsigned char *offset = 0;
|
|
|
|
msg.content = (void*) (offset + ZMQ_DELIMITER);
|
2010-03-09 16:56:53 +01:00
|
|
|
msg.flags = 0;
|
2010-05-19 06:31:57 +02:00
|
|
|
pipe->write (msg, false);
|
2010-06-19 20:46:16 +02:00
|
|
|
flush ();
|
2009-08-28 16:51:46 +02:00
|
|
|
}
|
|
|
|
|
2010-08-28 10:15:03 +02:00
|
|
|
void zmq::writer_t::process_activate_writer (uint64_t msgs_read_)
|
2010-03-01 10:13:26 +01:00
|
|
|
{
|
2010-08-28 13:06:58 +02:00
|
|
|
// Store the reader's message sequence number.
|
2010-03-01 10:13:26 +01:00
|
|
|
msgs_read = msgs_read_;
|
2010-06-21 15:06:51 +02:00
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
// If we are in the swapping mode, we have some messages in the swap.
|
|
|
|
// Given that pipe is now ready for writing we can move part of the
|
|
|
|
// swap into the pipe.
|
|
|
|
if (swapping) {
|
|
|
|
zmq_msg_t msg;
|
|
|
|
while (!pipe_full () && !swap->empty ()) {
|
|
|
|
swap->fetch(&msg);
|
2010-06-21 15:06:51 +02:00
|
|
|
pipe->write (msg, msg.flags & ZMQ_MSG_MORE);
|
|
|
|
if (!(msg.flags & ZMQ_MSG_MORE))
|
|
|
|
msgs_written++;
|
|
|
|
}
|
2010-08-28 13:06:58 +02:00
|
|
|
if (!pipe->flush ())
|
|
|
|
send_activate_reader (reader);
|
2010-06-21 15:06:51 +02:00
|
|
|
|
2010-09-13 13:27:48 +02:00
|
|
|
// There are no more messages in the swap. We can switch into
|
|
|
|
// standard in-memory mode.
|
|
|
|
if (swap->empty ()) {
|
|
|
|
swapping = false;
|
|
|
|
|
|
|
|
// Push delimiter into the pipe. Trick the compiler to belive that
|
|
|
|
// the tag is a valid pointer. Note that watermarks are not checked
|
|
|
|
// thus the delimiter can be written even though the pipe is full.
|
|
|
|
if (pending_delimiter) {
|
|
|
|
zmq_msg_t msg;
|
|
|
|
const unsigned char *offset = 0;
|
|
|
|
msg.content = (void*) (offset + ZMQ_DELIMITER);
|
|
|
|
msg.flags = 0;
|
|
|
|
pipe->write (msg, false);
|
|
|
|
flush ();
|
|
|
|
return;
|
|
|
|
}
|
2010-06-21 15:06:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 13:06:58 +02:00
|
|
|
// If the writer was non-active before, let's make it active
|
|
|
|
// (available for writing messages to).
|
|
|
|
if (!active) {
|
|
|
|
active = true;
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq_assert (sink);
|
|
|
|
sink->activated (this);
|
2010-03-01 10:13:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-28 16:51:46 +02:00
|
|
|
void zmq::writer_t::process_pipe_term ()
|
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
send_pipe_term_ack (reader);
|
2009-08-28 16:51:46 +02:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
// The above command allows reader to deallocate itself and the pipe.
|
|
|
|
// For safety's sake we'll drop the pointers here.
|
|
|
|
reader = NULL;
|
|
|
|
pipe = NULL;
|
2009-08-28 16:51:46 +02:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
// Notify owner about the termination.
|
|
|
|
zmq_assert (sink);
|
|
|
|
sink->terminated (this);
|
2010-03-01 10:13:26 +01:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
// Deallocate the resources.
|
|
|
|
delete this;
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
bool zmq::writer_t::pipe_full ()
|
2009-08-27 10:54:28 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
return hwm > 0 && msgs_written - msgs_read == hwm;
|
2009-08-27 10:54:28 +02:00
|
|
|
}
|
2010-05-25 15:03:57 +02:00
|
|
|
|
2010-08-06 17:49:37 +02:00
|
|
|
void zmq::create_pipe (object_t *reader_parent_, object_t *writer_parent_,
|
|
|
|
uint64_t hwm_, int64_t swap_size_, reader_t **reader_, writer_t **writer_)
|
2010-05-25 15:03:57 +02:00
|
|
|
{
|
2010-08-06 17:49:37 +02:00
|
|
|
// First compute the low water mark. Following point should be taken
|
|
|
|
// into consideration:
|
|
|
|
//
|
|
|
|
// 1. LWM has to be less than HWM.
|
|
|
|
// 2. LWM cannot be set to very low value (such as zero) as after filling
|
|
|
|
// the queue it would start to refill only after all the messages are
|
|
|
|
// read from it and thus unnecessarily hold the progress back.
|
|
|
|
// 3. LWM cannot be set to very high value (such as HWM-1) as it would
|
|
|
|
// result in lock-step filling of the queue - if a single message is
|
|
|
|
// read from a full queue, writer thread is resumed to write exactly one
|
|
|
|
// message to the queue and go back to sleep immediately. This would
|
|
|
|
// result in low performance.
|
|
|
|
//
|
|
|
|
// Given the 3. it would be good to keep HWM and LWM as far apart as
|
|
|
|
// possible to reduce the thread switching overhead to almost zero,
|
|
|
|
// say HWM-LWM should be max_wm_delta.
|
|
|
|
//
|
|
|
|
// That done, we still we have to account for the cases where
|
|
|
|
// HWM < max_wm_delta thus driving LWM to negative numbers.
|
|
|
|
// Let's make LWM 1/2 of HWM in such cases.
|
|
|
|
uint64_t lwm = (hwm_ > max_wm_delta * 2) ?
|
|
|
|
hwm_ - max_wm_delta : (hwm_ + 1) / 2;
|
|
|
|
|
|
|
|
// Create all three objects pipe consists of: the pipe per se, reader and
|
|
|
|
// writer. The pipe will be handled by reader and writer, its never passed
|
|
|
|
// to the user. Reader and writer are returned to the user.
|
|
|
|
pipe_t *pipe = new (std::nothrow) pipe_t ();
|
|
|
|
zmq_assert (pipe);
|
|
|
|
*reader_ = new (std::nothrow) reader_t (reader_parent_, pipe, lwm);
|
|
|
|
zmq_assert (*reader_);
|
|
|
|
*writer_ = new (std::nothrow) writer_t (writer_parent_, pipe, *reader_,
|
|
|
|
hwm_, swap_size_);
|
|
|
|
zmq_assert (*writer_);
|
2010-05-25 15:03:57 +02:00
|
|
|
}
|