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

« back to all changes in this revision

Viewing changes to src/dist.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) 2011 250bpm s.r.o.
 
3
    Copyright (c) 2011 Other contributors as noted in the AUTHORS file
 
4
 
 
5
    This file is part of 0MQ.
 
6
 
 
7
    0MQ is free software; you can redistribute it and/or modify it under
 
8
    the terms of the GNU Lesser General Public License as published by
 
9
    the Free Software Foundation; either version 3 of the License, or
 
10
    (at your option) any later version.
 
11
 
 
12
    0MQ is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU Lesser General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Lesser General Public License
 
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#ifndef __ZMQ_DIST_HPP_INCLUDED__
 
22
#define __ZMQ_DIST_HPP_INCLUDED__
 
23
 
 
24
#include <vector>
 
25
 
 
26
#include "array.hpp"
 
27
#include "pipe.hpp"
 
28
 
 
29
namespace zmq
 
30
{
 
31
 
 
32
    class pipe_t;
 
33
    class msg_t;
 
34
 
 
35
    //  Class manages a set of outbound pipes. It sends each messages to
 
36
    //  each of them.
 
37
    class dist_t
 
38
    {
 
39
    public:
 
40
 
 
41
        dist_t ();
 
42
        ~dist_t ();
 
43
 
 
44
        //  Adds the pipe to the distributor object.
 
45
        void attach (zmq::pipe_t *pipe_);
 
46
 
 
47
        //  Activates pipe that have previously reached high watermark.
 
48
        void activated (zmq::pipe_t *pipe_);
 
49
 
 
50
        //  Mark the pipe as matching. Subsequent call to send_to_matching
 
51
        //  will send message also to this pipe.
 
52
        void match (zmq::pipe_t *pipe_);
 
53
 
 
54
        //  Mark all pipes as non-matching.
 
55
        void unmatch ();
 
56
 
 
57
        //  Removes the pipe from the distributor object.
 
58
        void terminated (zmq::pipe_t *pipe_);
 
59
 
 
60
        //  Send the message to the matching outbound pipes.
 
61
        int send_to_matching (zmq::msg_t *msg_, int flags_);
 
62
 
 
63
        //  Send the message to all the outbound pipes.
 
64
        int send_to_all (zmq::msg_t *msg_, int flags_);
 
65
 
 
66
        bool has_out ();
 
67
 
 
68
    private:
 
69
 
 
70
        //  Write the message to the pipe. Make the pipe inactive if writing
 
71
        //  fails. In such a case false is returned.
 
72
        bool write (zmq::pipe_t *pipe_, zmq::msg_t *msg_);
 
73
 
 
74
        //  Put the message to all active pipes.
 
75
        void distribute (zmq::msg_t *msg_, int flags_);
 
76
 
 
77
        //  List of outbound pipes.
 
78
        typedef array_t <zmq::pipe_t, 2> pipes_t;
 
79
        pipes_t pipes;
 
80
 
 
81
        //  Number of all the pipes to send the next message to.
 
82
        pipes_t::size_type matching;
 
83
 
 
84
        //  Number of active pipes. All the active pipes are located at the
 
85
        //  beginning of the pipes array. These are the pipes the messages
 
86
        //  can be sent to at the moment.
 
87
        pipes_t::size_type active;
 
88
 
 
89
        //  Number of pipes eligible for sending messages to. This includes all
 
90
        //  the active pipes plus all the pipes that we can in theory send
 
91
        //  messages to (the HWM is not yet reached), but sending a message
 
92
        //  to them would result in partial message being delivered, ie. message
 
93
        //  with initial parts missing.
 
94
        pipes_t::size_type eligible;
 
95
 
 
96
        //  True if last we are in the middle of a multipart message.
 
97
        bool more;
 
98
 
 
99
        dist_t (const dist_t&);
 
100
        const dist_t &operator = (const dist_t&);
 
101
    };
 
102
 
 
103
}
 
104
 
 
105
#endif