2009-12-15 09:09:19 +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
|
2009-12-15 09:09:19 +01:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2009-12-15 09:09:19 +01:00
|
|
|
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
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2009-12-15 09:09:19 +01:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-12-15 09:09:19 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZMQ_LB_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_LB_HPP_INCLUDED__
|
|
|
|
|
2010-08-31 21:03:34 +02:00
|
|
|
#include "array.hpp"
|
2010-08-06 17:49:37 +02:00
|
|
|
#include "pipe.hpp"
|
2009-12-15 09:09:19 +01:00
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
// This class manages a set of outbound pipes. On send it load balances
|
2009-12-15 09:09:19 +01:00
|
|
|
// messages fairly among the pipes.
|
2011-05-22 17:26:53 +02:00
|
|
|
|
|
|
|
class lb_t
|
2009-12-15 09:09:19 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-09-18 07:37:36 +02:00
|
|
|
lb_t (class own_t *sink_);
|
2009-12-15 09:09:19 +01:00
|
|
|
~lb_t ();
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
void attach (pipe_t *pipe_);
|
2010-08-11 14:09:56 +02:00
|
|
|
void terminate ();
|
2011-04-21 22:27:48 +02:00
|
|
|
int send (msg_t *msg_, int flags_);
|
2009-12-15 09:09:19 +01:00
|
|
|
bool has_out ();
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
void activated (pipe_t *pipe_);
|
|
|
|
void terminated (pipe_t *pipe_);
|
2010-08-06 17:49:37 +02:00
|
|
|
|
2009-12-15 09:09:19 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
// List of outbound pipes.
|
2011-05-22 17:26:53 +02:00
|
|
|
typedef array_t <class pipe_t, 2> pipes_t;
|
2009-12-15 09:09:19 +01:00
|
|
|
pipes_t pipes;
|
|
|
|
|
|
|
|
// Number of active pipes. All the active pipes are located at the
|
|
|
|
// beginning of the pipes array.
|
|
|
|
pipes_t::size_type active;
|
|
|
|
|
|
|
|
// Points to the last pipe that the most recent message was sent to.
|
|
|
|
pipes_t::size_type current;
|
|
|
|
|
2010-03-27 09:43:49 +01:00
|
|
|
// True if last we are in the middle of a multipart message.
|
2010-03-27 21:25:40 +01:00
|
|
|
bool more;
|
2010-03-27 09:43:49 +01:00
|
|
|
|
2011-03-20 20:52:54 +01:00
|
|
|
// True if we are dropping current message.
|
|
|
|
bool dropping;
|
|
|
|
|
2010-08-11 14:09:56 +02:00
|
|
|
// Object to send events to.
|
2010-09-18 07:37:36 +02:00
|
|
|
class own_t *sink;
|
2010-08-11 14:09:56 +02:00
|
|
|
|
|
|
|
// If true, termination process is already underway.
|
|
|
|
bool terminating;
|
|
|
|
|
2009-12-15 09:09:19 +01:00
|
|
|
lb_t (const lb_t&);
|
2011-01-13 11:44:23 +01:00
|
|
|
const lb_t &operator = (const lb_t&);
|
2009-12-15 09:09:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|