libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
io_thread.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_IO_THREAD_HPP_INCLUDED__
31 #define __ZMQ_IO_THREAD_HPP_INCLUDED__
32 
33 #include <vector>
34 
35 #include "stdint.hpp"
36 #include "object.hpp"
37 #include "poller.hpp"
38 #include "i_poll_events.hpp"
39 #include "mailbox.hpp"
40 
41 namespace zmq
42 {
43 
44  class ctx_t;
45 
46  // Generic part of the I/O thread. Polling-mechanism-specific features
47  // are implemented in separate "polling objects".
48 
49  class io_thread_t : public object_t, public i_poll_events
50  {
51  public:
52 
53  io_thread_t (zmq::ctx_t *ctx_, uint32_t tid_);
54 
55  // Clean-up. If the thread was started, it's necessary to call 'stop'
56  // before invoking destructor. Otherwise the destructor would hang up.
57  ~io_thread_t ();
58 
59  // Launch the physical thread.
60  void start ();
61 
62  // Ask underlying thread to stop.
63  void stop ();
64 
65  // Returns mailbox associated with this I/O thread.
67 
68  // i_poll_events implementation.
69  void in_event ();
70  void out_event ();
71  void timer_event (int id_);
72 
73  // Used by io_objects to retrieve the associated poller object.
74  poller_t *get_poller ();
75 
76  // Command handlers.
77  void process_stop ();
78 
79  // Returns load experienced by the I/O thread.
80  int get_load ();
81 
82  private:
83 
84  // I/O thread accesses incoming commands via this mailbox.
86 
87  // Handle associated with mailbox' file descriptor.
88  poller_t::handle_t mailbox_handle;
89 
90  // I/O multiplexing is performed using a poller object.
91  poller_t *poller;
92 
93  io_thread_t (const io_thread_t&);
94  const io_thread_t &operator = (const io_thread_t&);
95  };
96 
97 }
98 
99 #endif
poller_t::handle_t mailbox_handle
Definition: io_thread.hpp:88
mailbox_t mailbox
Definition: io_thread.hpp:85
poller_t * get_poller()
Definition: io_thread.cpp:104
poller_t * poller
Definition: io_thread.hpp:91
const io_thread_t & operator=(const io_thread_t &)
void timer_event(int id_)
Definition: io_thread.cpp:98
io_thread_t(zmq::ctx_t *ctx_, uint32_t tid_)
Definition: io_thread.cpp:39
Definition: address.hpp:35
mailbox_t * get_mailbox()
Definition: io_thread.cpp:65