Commit f2ff2c6e authored by Martin Sustrik's avatar Martin Sustrik

checking for available messages added to ypipe/pipe

parent 84d854a0
...@@ -36,6 +36,17 @@ zmq::reader_t::~reader_t () ...@@ -36,6 +36,17 @@ zmq::reader_t::~reader_t ()
{ {
} }
bool zmq::reader_t::check_read ()
{
// Check if there's an item in the pipe.
if (pipe->check_read ())
return true;
// If not, deactivate the pipe.
endpoint->kill (this);
return false;
}
bool zmq::reader_t::read (zmq_msg_t *msg_) bool zmq::reader_t::read (zmq_msg_t *msg_)
{ {
if (!pipe->read (msg_)) { if (!pipe->read (msg_)) {
......
...@@ -42,6 +42,9 @@ namespace zmq ...@@ -42,6 +42,9 @@ namespace zmq
void set_endpoint (i_endpoint *endpoint_); void set_endpoint (i_endpoint *endpoint_);
// Returns true if there is at least one message to read in the pipe.
bool check_read ();
// Reads a message to the underlying pipe. // Reads a message to the underlying pipe.
bool read (zmq_msg_t *msg_); bool read (zmq_msg_t *msg_);
......
...@@ -106,16 +106,12 @@ namespace zmq ...@@ -106,16 +106,12 @@ namespace zmq
return true; return true;
} }
// Reads an item from the pipe. Returns false if there is no value. // Check whether item is available for reading.
// available. inline bool check_read ()
inline bool read (T *value_)
{ {
// Was the value prefetched already? If so, return it. // Was the value prefetched already? If so, return.
if (&queue.front () != r) { if (&queue.front () != r)
*value_ = queue.front ();
queue.pop ();
return true; return true;
}
// There's no prefetched value, so let us prefetch more values. // There's no prefetched value, so let us prefetch more values.
// (Note that D is a template parameter. Becaue of that one of // (Note that D is a template parameter. Becaue of that one of
...@@ -165,6 +161,18 @@ namespace zmq ...@@ -165,6 +161,18 @@ namespace zmq
return false; return false;
} }
// There was at least one value prefetched.
return true;
}
// Reads an item from the pipe. Returns false if there is no value.
// available.
inline bool read (T *value_)
{
// Try to prefetch a value.
if (!check_read ())
return false;
// There was at least one value prefetched. // There was at least one value prefetched.
// Return it to the caller. // Return it to the caller.
*value_ = queue.front (); *value_ = queue.front ();
......
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