0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-29 00:32:34 +08:00

Simplify implementation of DEALER socket

This commit is contained in:
Martin Hurton 2012-11-09 15:45:25 +01:00
parent d1e0889ab0
commit b78800e467
2 changed files with 2 additions and 30 deletions

View File

@ -24,8 +24,7 @@
#include "msg.hpp"
zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
socket_base_t (parent_, tid_, sid_),
prefetched (false)
socket_base_t (parent_, tid_, sid_)
{
options.type = ZMQ_DEALER;
@ -34,13 +33,10 @@ zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
// If the socket is closing we can drop all the outbound requests. There'll
// be noone to receive the replies anyway.
// options.delay_on_close = false;
prefetched_msg.init ();
}
zmq::dealer_t::~dealer_t ()
{
prefetched_msg.close ();
}
void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
@ -63,30 +59,12 @@ int zmq::dealer_t::xrecv (msg_t *msg_, int flags_)
// flags_ is unused
(void)flags_;
// If there is a prefetched message, return it.
if (prefetched) {
int rc = msg_->move (prefetched_msg);
errno_assert (rc == 0);
prefetched = false;
return 0;
}
return fq.recv (msg_);
}
bool zmq::dealer_t::xhas_in ()
{
// We may already have a message pre-fetched.
if (prefetched)
return true;
// Try to read the next message to the pre-fetch buffer.
int rc = dealer_t::xrecv (&prefetched_msg, ZMQ_DONTWAIT);
if (rc != 0 && errno == EAGAIN)
return false;
errno_assert (rc == 0);
prefetched = true;
return true;
return fq.has_in ();
}
bool zmq::dealer_t::xhas_out ()

View File

@ -62,12 +62,6 @@ namespace zmq
fq_t fq;
lb_t lb;
// Have we prefetched a message.
bool prefetched;
// Holds the prefetched message.
msg_t prefetched_msg;
dealer_t (const dealer_t&);
const dealer_t &operator = (const dealer_t&);
};