Coverage Report

Created: 2025-10-13 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libzmq/src/mailbox.hpp
Line
Count
Source
1
/* SPDX-License-Identifier: MPL-2.0 */
2
3
#ifndef __ZMQ_MAILBOX_HPP_INCLUDED__
4
#define __ZMQ_MAILBOX_HPP_INCLUDED__
5
6
#include <stddef.h>
7
8
#include "signaler.hpp"
9
#include "fd.hpp"
10
#include "config.hpp"
11
#include "command.hpp"
12
#include "ypipe.hpp"
13
#include "mutex.hpp"
14
#include "i_mailbox.hpp"
15
16
namespace zmq
17
{
18
class mailbox_t ZMQ_FINAL : public i_mailbox
19
{
20
  public:
21
    mailbox_t ();
22
    ~mailbox_t ();
23
24
    fd_t get_fd () const;
25
    void send (const command_t &cmd_);
26
    int recv (command_t *cmd_, int timeout_);
27
28
    bool valid () const;
29
30
#ifdef HAVE_FORK
31
    // close the file descriptors in the signaller. This is used in a forked
32
    // child process to close the file descriptors so that they do not interfere
33
    // with the context in the parent process.
34
0
    void forked () ZMQ_FINAL { _signaler.forked (); }
35
#endif
36
37
  private:
38
    //  The pipe to store actual commands.
39
    typedef ypipe_t<command_t, command_pipe_granularity> cpipe_t;
40
    cpipe_t _cpipe;
41
42
    //  Signaler to pass signals from writer thread to reader thread.
43
    signaler_t _signaler;
44
45
    //  There's only one thread receiving from the mailbox, but there
46
    //  is arbitrary number of threads sending. Given that ypipe requires
47
    //  synchronised access on both of its endpoints, we have to synchronise
48
    //  the sending side.
49
    mutex_t _sync;
50
51
    //  True if the underlying pipe is active, ie. when we are allowed to
52
    //  read commands from it.
53
    bool _active;
54
55
    ZMQ_NON_COPYABLE_NOR_MOVABLE (mailbox_t)
56
};
57
}
58
59
#endif