Commit b78800e4 authored by Martin Hurton's avatar Martin Hurton

Simplify implementation of DEALER socket

parent d1e0889a
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
#include "msg.hpp" #include "msg.hpp"
zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) : zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
socket_base_t (parent_, tid_, sid_), socket_base_t (parent_, tid_, sid_)
prefetched (false)
{ {
options.type = ZMQ_DEALER; options.type = ZMQ_DEALER;
...@@ -34,13 +33,10 @@ zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) : ...@@ -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 // If the socket is closing we can drop all the outbound requests. There'll
// be noone to receive the replies anyway. // be noone to receive the replies anyway.
// options.delay_on_close = false; // options.delay_on_close = false;
prefetched_msg.init ();
} }
zmq::dealer_t::~dealer_t () zmq::dealer_t::~dealer_t ()
{ {
prefetched_msg.close ();
} }
void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_) 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_) ...@@ -63,30 +59,12 @@ int zmq::dealer_t::xrecv (msg_t *msg_, int flags_)
// flags_ is unused // flags_ is unused
(void)flags_; (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_); return fq.recv (msg_);
} }
bool zmq::dealer_t::xhas_in () bool zmq::dealer_t::xhas_in ()
{ {
// We may already have a message pre-fetched. return fq.has_in ();
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;
} }
bool zmq::dealer_t::xhas_out () bool zmq::dealer_t::xhas_out ()
......
...@@ -62,12 +62,6 @@ namespace zmq ...@@ -62,12 +62,6 @@ namespace zmq
fq_t fq; fq_t fq;
lb_t lb; lb_t lb;
// Have we prefetched a message.
bool prefetched;
// Holds the prefetched message.
msg_t prefetched_msg;
dealer_t (const dealer_t&); dealer_t (const dealer_t&);
const dealer_t &operator = (const dealer_t&); const dealer_t &operator = (const dealer_t&);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment