~ubuntu-branches/ubuntu/precise/zeromq/precise

« back to all changes in this revision

Viewing changes to src/dist.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Lucina
  • Date: 2011-05-13 12:43:09 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110513124309-m3gdt964ga67rcwu
Tags: 2.1.7-1
* New upstream version. (closes: #619374)
* --with-system-pgm is now used instead of the embedded OpenPGM library. 
* Added Debian watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2007-2011 iMatix Corporation
 
3
    Copyright (c) 2007-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 manages a set of outbound pipes. It sends each messages to
 
33
    //  each of them.
 
34
    class dist_t : public i_writer_events
 
35
    {
 
36
    public:
 
37
 
 
38
        dist_t (class own_t *sink_);
 
39
        ~dist_t ();
 
40
 
 
41
        void attach (writer_t *pipe_);
 
42
        void terminate ();
 
43
        int send (zmq_msg_t *msg_, int flags_);
 
44
        bool has_out ();
 
45
 
 
46
        //  i_writer_events interface implementation.
 
47
        void activated (writer_t *pipe_);
 
48
        void terminated (writer_t *pipe_);
 
49
 
 
50
    private:
 
51
 
 
52
        //  Write the message to the pipe. Make the pipe inactive if writing
 
53
        //  fails. In such a case false is returned.
 
54
        bool write (class writer_t *pipe_, zmq_msg_t *msg_);
 
55
 
 
56
        //  Put the message to all active pipes.
 
57
        void distribute (zmq_msg_t *msg_, int flags_);
 
58
 
 
59
        //  List of outbound pipes.
 
60
        typedef array_t <class writer_t> pipes_t;
 
61
        pipes_t pipes;
 
62
 
 
63
        //  Number of active pipes. All the active pipes are located at the
 
64
        //  beginning of the pipes array. These are the pipes the messages
 
65
        //  can be sent to at the moment.
 
66
        pipes_t::size_type active;
 
67
 
 
68
        //  Number of pipes eligible for sending messages to. This includes all
 
69
        //  the active pipes plus all the pipes that we can in theory send
 
70
        //  messages to (the HWM is not yet reached), but sending a message
 
71
        //  to them would result in partial message being delivered, ie. message
 
72
        //  with initial parts missing.
 
73
        pipes_t::size_type eligible;
 
74
 
 
75
        //  True if last we are in the middle of a multipart message.
 
76
        bool more;
 
77
 
 
78
        //  Object to send events to.
 
79
        class own_t *sink;
 
80
 
 
81
        //  If true, termination process is already underway.
 
82
        bool terminating;
 
83
 
 
84
        dist_t (const dist_t&);
 
85
        const dist_t &operator = (const dist_t&);
 
86
    };
 
87
 
 
88
}
 
89
 
 
90
#endif