ypipe_conflate.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_YPIPE_CONFLATE_HPP_INCLUDED__
4 #define __ZMQ_YPIPE_CONFLATE_HPP_INCLUDED__
5 
6 #include "platform.hpp"
7 #include "dbuffer.hpp"
8 #include "ypipe_base.hpp"
9 
10 namespace zmq
11 {
12 // Adapter for dbuffer, to plug it in instead of a queue for the sake
13 // of implementing the conflate socket option, which, if set, makes
14 // the receiving side to discard all incoming messages but the last one.
15 //
16 // reader_awake flag is needed here to mimic ypipe delicate behaviour
17 // around the reader being asleep (see 'c' pointer being NULL in ypipe.hpp)
18 
19 template <typename T> class ypipe_conflate_t ZMQ_FINAL : public ypipe_base_t<T>
20 {
21  public:
22  // Initialises the pipe.
23  ypipe_conflate_t () : reader_awake (false) {}
24 
25  // Following function (write) deliberately copies uninitialised data
26  // when used with zmq_msg. Initialising the VSM body for
27  // non-VSM messages won't be good for performance.
28 
29 #ifdef ZMQ_HAVE_OPENVMS
30 #pragma message save
31 #pragma message disable(UNINIT)
32 #endif
33  void write (const T &value_, bool incomplete_)
34  {
35  (void) incomplete_;
36 
37  dbuffer.write (value_);
38  }
39 
40 #ifdef ZMQ_HAVE_OPENVMS
41 #pragma message restore
42 #endif
43 
44  // There are no incomplete items for conflate ypipe
45  bool unwrite (T *)
46  {
47  return false;
48  }
49 
50  // Flush is no-op for conflate ypipe. Reader asleep behaviour
51  // is as of the usual ypipe.
52  // Returns false if the reader thread is sleeping. In that case,
53  // caller is obliged to wake the reader up before using the pipe again.
54  bool flush ()
55  {
56  return reader_awake;
57  }
58 
59  // Check whether item is available for reading.
60  bool check_read ()
61  {
62  const bool res = dbuffer.check_read ();
63  if (!res)
64  reader_awake = false;
65 
66  return res;
67  }
68 
69  // Reads an item from the pipe. Returns false if there is no value.
70  // available.
71  bool read (T *value_)
72  {
73  if (!check_read ())
74  return false;
75 
76  return dbuffer.read (value_);
77  }
78 
79  // Applies the function fn to the first element in the pipe
80  // and returns the value returned by the fn.
81  // The pipe mustn't be empty or the function crashes.
82  bool probe (bool (*fn_) (const T &))
83  {
84  return dbuffer.probe (fn_);
85  }
86 
87  protected:
90 
91  ZMQ_NON_COPYABLE_NOR_MOVABLE (ypipe_conflate_t)
92 };
93 }
94 
95 #endif
zmq::ZMQ_FINAL::check_read
bool check_read()
Definition: ypipe_conflate.hpp:60
zmq::ZMQ_FINAL::dbuffer
dbuffer_t< T > dbuffer
Definition: ypipe_conflate.hpp:88
ypipe_base.hpp
T
#define T(upbtypeconst, upbtype, ctype, default_value)
zmq::ZMQ_FINAL::reader_awake
bool reader_awake
Definition: ypipe_conflate.hpp:89
zmq
Definition: zmq.hpp:229
zmq::ZMQ_FINAL::flush
bool flush()
Definition: ypipe_conflate.hpp:54
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
zmq::dbuffer_t
Definition: dbuffer.hpp:29
zmq::ZMQ_FINAL::read
bool read(T *value_)
Definition: ypipe_conflate.hpp:71
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
value_
int value_
Definition: gmock-matchers_test.cc:571
zmq::ZMQ_FINAL::probe
bool probe(bool(*fn_)(const T &))
Definition: ypipe_conflate.hpp:82
zmq::ZMQ_FINAL::unwrite
bool unwrite(T *)
Definition: ypipe_conflate.hpp:45
zmq::ZMQ_FINAL::write
void write(const T &value_, bool incomplete_)
Definition: ypipe_conflate.hpp:33
false
#define false
Definition: cJSON.c:70
ZMQ_FINAL
Definition: unittest_ip_resolver.cpp:26
zmq::ZMQ_FINAL::ypipe_conflate_t
ypipe_conflate_t()
Definition: ypipe_conflate.hpp:23
dbuffer.hpp


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:02