mailbox_safe.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_MAILBOX_SAFE_HPP_INCLUDED__
4 #define __ZMQ_MAILBOX_SAFE_HPP_INCLUDED__
5 
6 #include <vector>
7 #include <stddef.h>
8 
9 #include "signaler.hpp"
10 #include "fd.hpp"
11 #include "config.hpp"
12 #include "command.hpp"
13 #include "ypipe.hpp"
14 #include "mutex.hpp"
15 #include "i_mailbox.hpp"
16 #include "condition_variable.hpp"
17 
18 namespace zmq
19 {
20 class mailbox_safe_t ZMQ_FINAL : public i_mailbox
21 {
22  public:
23  mailbox_safe_t (mutex_t *sync_);
24  ~mailbox_safe_t ();
25 
26  void send (const command_t &cmd_);
27  int recv (command_t *cmd_, int timeout_);
28 
29  // Add signaler to mailbox which will be called when a message is ready
30  void add_signaler (signaler_t *signaler_);
31  void remove_signaler (signaler_t *signaler_);
32  void clear_signalers ();
33 
34 #ifdef HAVE_FORK
35  // close the file descriptors in the signaller. This is used in a forked
36  // child process to close the file descriptors so that they do not interfere
37  // with the context in the parent process.
38  void forked () ZMQ_FINAL
39  {
40  // TODO: call fork on the condition variable
41  }
42 #endif
43 
44  private:
45  // The pipe to store actual commands.
46  typedef ypipe_t<command_t, command_pipe_granularity> cpipe_t;
47  cpipe_t _cpipe;
48 
49  // Condition variable to pass signals from writer thread to reader thread.
50  condition_variable_t _cond_var;
51 
52  // Synchronize access to the mailbox from receivers and senders
53  mutex_t *const _sync;
54 
55  std::vector<zmq::signaler_t *> _signalers;
56 
57  ZMQ_NON_COPYABLE_NOR_MOVABLE (mailbox_safe_t)
58 };
59 }
60 
61 #endif
zmq::ZMQ_FINAL::_signalers
std::vector< zmq::signaler_t * > _signalers
Definition: mailbox_safe.hpp:55
config.hpp
ypipe.hpp
zmq::ZMQ_FINAL::cpipe_t
ypipe_t< command_t, command_pipe_granularity > cpipe_t
Definition: mailbox_safe.hpp:46
zmq::ZMQ_FINAL::_cond_var
condition_variable_t _cond_var
Definition: mailbox_safe.hpp:50
send
void send(fd_t fd_, const char(&data_)[N])
Definition: test_security_curve.cpp:209
command.hpp
zmq
Definition: zmq.hpp:229
i_mailbox.hpp
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
fd.hpp
zmq::ZMQ_FINAL::_sync
mutex_t *const _sync
Definition: mailbox_safe.hpp:53
zmq::mutex_t
Definition: mutex.hpp:82
condition_variable.hpp
signaler.hpp
ZMQ_FINAL
Definition: unittest_ip_resolver.cpp:26
mutex.hpp


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