~ubuntu-branches/ubuntu/saucy/zeromq3/saucy

« back to all changes in this revision

Viewing changes to src/io_thread.hpp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-06-04 21:21:09 UTC
  • Revision ID: package-import@ubuntu.com-20120604212109-b7b3m0rn21o8oo2q
Tags: upstream-3.1.0~beta+dfsg
ImportĀ upstreamĀ versionĀ 3.1.0~beta+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2009-2011 250bpm s.r.o.
 
3
    Copyright (c) 2007-2009 iMatix Corporation
 
4
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
 
5
 
 
6
    This file is part of 0MQ.
 
7
 
 
8
    0MQ is free software; you can redistribute it and/or modify it under
 
9
    the terms of the GNU Lesser General Public License as published by
 
10
    the Free Software Foundation; either version 3 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    0MQ is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public License
 
19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#ifndef __ZMQ_IO_THREAD_HPP_INCLUDED__
 
23
#define __ZMQ_IO_THREAD_HPP_INCLUDED__
 
24
 
 
25
#include <vector>
 
26
 
 
27
#include "stdint.hpp"
 
28
#include "object.hpp"
 
29
#include "poller.hpp"
 
30
#include "i_poll_events.hpp"
 
31
#include "mailbox.hpp"
 
32
 
 
33
namespace zmq
 
34
{
 
35
 
 
36
    class ctx_t;
 
37
 
 
38
    //  Generic part of the I/O thread. Polling-mechanism-specific features
 
39
    //  are implemented in separate "polling objects".
 
40
 
 
41
    class io_thread_t : public object_t, public i_poll_events
 
42
    {
 
43
    public:
 
44
 
 
45
        io_thread_t (zmq::ctx_t *ctx_, uint32_t tid_);
 
46
 
 
47
        //  Clean-up. If the thread was started, it's neccessary to call 'stop'
 
48
        //  before invoking destructor. Otherwise the destructor would hang up.
 
49
        ~io_thread_t ();
 
50
 
 
51
        //  Launch the physical thread.
 
52
        void start ();
 
53
 
 
54
        //  Ask underlying thread to stop.
 
55
        void stop ();
 
56
 
 
57
        //  Returns mailbox associated with this I/O thread.
 
58
        mailbox_t *get_mailbox ();
 
59
 
 
60
        //  i_poll_events implementation.
 
61
        void in_event ();
 
62
        void out_event ();
 
63
        void timer_event (int id_);
 
64
 
 
65
        //  Used by io_objects to retrieve the assciated poller object.
 
66
        poller_t *get_poller ();
 
67
 
 
68
        //  Command handlers.
 
69
        void process_stop ();
 
70
 
 
71
        //  Returns load experienced by the I/O thread.
 
72
        int get_load ();
 
73
 
 
74
    private:
 
75
 
 
76
        //  I/O thread accesses incoming commands via this mailbox.
 
77
        mailbox_t mailbox;
 
78
 
 
79
        //  Handle associated with mailbox' file descriptor.
 
80
        poller_t::handle_t mailbox_handle;
 
81
 
 
82
        //  I/O multiplexing is performed using a poller object.
 
83
        poller_t *poller;
 
84
 
 
85
        io_thread_t (const io_thread_t&);
 
86
        const io_thread_t &operator = (const io_thread_t&);
 
87
    };
 
88
 
 
89
}
 
90
 
 
91
#endif