Do not crash when multiple peers connect to PAIR socket

When more then one peer connected to a ZMQ_PAIR socket,
an application aborted due to assertion failure.
This patch changes the ZMQ_PAIR socket behaviour so that
it rejects any further connection requests.
This commit is contained in:
Martin Hurton 2012-04-30 00:48:07 +02:00
parent 16ec2868c5
commit d84709497e

View File

@ -38,14 +38,20 @@ zmq::pair_t::~pair_t ()
void zmq::pair_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_) void zmq::pair_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
{ {
zmq_assert (!pipe); zmq_assert (pipe_ != NULL);
pipe = pipe_;
// ZMQ_PAIR socket can only be connected to a single peer.
// The socket rejects any further connection requests.
if (pipe == NULL)
pipe = pipe_;
else
pipe_->terminate (false);
} }
void zmq::pair_t::xterminated (pipe_t *pipe_) void zmq::pair_t::xterminated (pipe_t *pipe_)
{ {
zmq_assert (pipe_ == pipe); if (pipe_ == pipe)
pipe = NULL; pipe = NULL;
} }
void zmq::pair_t::xread_activated (pipe_t *pipe_) void zmq::pair_t::xread_activated (pipe_t *pipe_)