2023-06-05 01:16:05 +02:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2011-02-09 15:32:15 +01:00
|
|
|
|
|
|
|
#ifndef __ZMQ_REAPER_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_REAPER_HPP_INCLUDED__
|
|
|
|
|
|
|
|
#include "object.hpp"
|
|
|
|
#include "mailbox.hpp"
|
|
|
|
#include "poller.hpp"
|
|
|
|
#include "i_poll_events.hpp"
|
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
2011-11-09 15:22:20 +01:00
|
|
|
class ctx_t;
|
|
|
|
class socket_base_t;
|
2011-02-09 15:32:15 +01:00
|
|
|
|
2019-12-24 10:39:26 +01:00
|
|
|
class reaper_t ZMQ_FINAL : public object_t, public i_poll_events
|
2011-02-09 15:32:15 +01:00
|
|
|
{
|
|
|
|
public:
|
2011-11-09 15:22:20 +01:00
|
|
|
reaper_t (zmq::ctx_t *ctx_, uint32_t tid_);
|
2020-02-04 11:57:58 +01:00
|
|
|
~reaper_t ();
|
2011-02-09 15:32:15 +01:00
|
|
|
|
|
|
|
mailbox_t *get_mailbox ();
|
|
|
|
|
|
|
|
void start ();
|
|
|
|
void stop ();
|
|
|
|
|
|
|
|
// i_poll_events implementation.
|
2020-02-04 11:57:58 +01:00
|
|
|
void in_event ();
|
|
|
|
void out_event ();
|
|
|
|
void timer_event (int id_);
|
2011-02-09 15:32:15 +01:00
|
|
|
|
2018-02-01 11:46:09 +01:00
|
|
|
private:
|
2011-02-09 15:32:15 +01:00
|
|
|
// Command handlers.
|
2020-02-04 11:57:58 +01:00
|
|
|
void process_stop ();
|
|
|
|
void process_reap (zmq::socket_base_t *socket_);
|
|
|
|
void process_reaped ();
|
2011-02-09 15:32:15 +01:00
|
|
|
|
|
|
|
// Reaper thread accesses incoming commands via this mailbox.
|
2018-05-27 11:10:39 +02:00
|
|
|
mailbox_t _mailbox;
|
2011-02-09 15:32:15 +01:00
|
|
|
|
|
|
|
// Handle associated with mailbox' file descriptor.
|
2018-05-27 11:10:39 +02:00
|
|
|
poller_t::handle_t _mailbox_handle;
|
2011-02-09 15:32:15 +01:00
|
|
|
|
|
|
|
// I/O multiplexing is performed using a poller object.
|
2018-05-27 11:10:39 +02:00
|
|
|
poller_t *_poller;
|
2011-02-09 15:32:15 +01:00
|
|
|
|
2011-02-09 22:23:21 +01:00
|
|
|
// Number of sockets being reaped at the moment.
|
2018-05-27 11:10:39 +02:00
|
|
|
int _sockets;
|
2011-02-09 22:23:21 +01:00
|
|
|
|
2011-02-09 15:32:15 +01:00
|
|
|
// If true, we were already asked to terminate.
|
2018-05-27 11:10:39 +02:00
|
|
|
bool _terminating;
|
2011-02-09 15:32:15 +01:00
|
|
|
|
2013-08-31 13:17:11 +02:00
|
|
|
#ifdef HAVE_FORK
|
|
|
|
// the process that created this context. Used to detect forking.
|
2018-05-27 11:10:39 +02:00
|
|
|
pid_t _pid;
|
2013-08-31 13:17:11 +02:00
|
|
|
#endif
|
2019-12-08 19:22:04 +01:00
|
|
|
|
|
|
|
ZMQ_NON_COPYABLE_NOR_MOVABLE (reaper_t)
|
2011-02-09 15:32:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|