2011-01-14 12:05:10 +01:00
|
|
|
/*
|
2011-03-02 16:30:40 +01:00
|
|
|
Copyright (c) 2007-2011 iMatix Corporation
|
|
|
|
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
2011-01-14 12:05:10 +01:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZMQ_DIST_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_DIST_HPP_INCLUDED__
|
|
|
|
|
2011-03-20 11:50:51 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2011-01-14 12:05:10 +01:00
|
|
|
#include "array.hpp"
|
|
|
|
#include "pipe.hpp"
|
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
|
|
|
|
// Class manages a set of outbound pipes. It sends each messages to
|
|
|
|
// each of them.
|
2011-05-22 17:26:53 +02:00
|
|
|
class dist_t
|
2011-01-14 12:05:10 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-05-23 20:30:01 +02:00
|
|
|
dist_t ();
|
2011-01-14 12:05:10 +01:00
|
|
|
~dist_t ();
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
void attach (class pipe_t *pipe_);
|
|
|
|
void activated (class pipe_t *pipe_);
|
|
|
|
void terminated (class pipe_t *pipe_);
|
2011-01-14 12:05:10 +01:00
|
|
|
|
2011-05-23 20:30:01 +02:00
|
|
|
int send (class msg_t *msg_, int flags_);
|
|
|
|
bool has_out ();
|
|
|
|
|
2011-01-14 12:05:10 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
// Write the message to the pipe. Make the pipe inactive if writing
|
|
|
|
// fails. In such a case false is returned.
|
2011-05-22 17:26:53 +02:00
|
|
|
bool write (class pipe_t *pipe_, class msg_t *msg_);
|
2011-01-14 12:05:10 +01:00
|
|
|
|
2011-03-20 11:50:51 +01:00
|
|
|
// Put the message to all active pipes.
|
2011-04-21 22:27:48 +02:00
|
|
|
void distribute (class msg_t *msg_, int flags_);
|
2011-03-20 11:50:51 +01:00
|
|
|
|
2011-01-14 12:05:10 +01:00
|
|
|
// List of outbound pipes.
|
2011-05-22 17:26:53 +02:00
|
|
|
typedef array_t <class pipe_t, 2> pipes_t;
|
2011-01-14 12:05:10 +01:00
|
|
|
pipes_t pipes;
|
|
|
|
|
|
|
|
// Number of active pipes. All the active pipes are located at the
|
2011-04-30 06:48:18 +02:00
|
|
|
// beginning of the pipes array. These are the pipes the messages
|
|
|
|
// can be sent to at the moment.
|
2011-01-14 12:05:10 +01:00
|
|
|
pipes_t::size_type active;
|
|
|
|
|
2011-04-30 06:48:18 +02:00
|
|
|
// Number of pipes eligible for sending messages to. This includes all
|
|
|
|
// the active pipes plus all the pipes that we can in theory send
|
|
|
|
// messages to (the HWM is not yet reached), but sending a message
|
|
|
|
// to them would result in partial message being delivered, ie. message
|
|
|
|
// with initial parts missing.
|
|
|
|
pipes_t::size_type eligible;
|
|
|
|
|
2011-01-14 12:05:10 +01:00
|
|
|
// True if last we are in the middle of a multipart message.
|
|
|
|
bool more;
|
|
|
|
|
|
|
|
dist_t (const dist_t&);
|
|
|
|
const dist_t &operator = (const dist_t&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|