2009-12-13 14:45:23 +01:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2009-12-13 14:45:23 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq 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.
|
2009-12-13 14:45:23 +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-13 14:45:23 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
#ifndef __ZMQ_ROUTER_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_ROUTER_HPP_INCLUDED__
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2010-02-16 18:30:38 +01:00
|
|
|
#include <map>
|
|
|
|
|
2009-12-13 14:45:23 +01:00
|
|
|
#include "socket_base.hpp"
|
2011-09-15 10:00:23 +02:00
|
|
|
#include "session_base.hpp"
|
2011-06-22 11:02:16 +02:00
|
|
|
#include "stdint.hpp"
|
2011-11-04 08:00:47 +01:00
|
|
|
#include "blob.hpp"
|
2011-04-21 22:27:48 +02:00
|
|
|
#include "msg.hpp"
|
2011-06-22 16:51:40 +02:00
|
|
|
#include "fq.hpp"
|
2009-12-13 14:45:23 +01:00
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
|
|
|
|
2011-11-09 15:22:20 +01:00
|
|
|
class ctx_t;
|
|
|
|
class pipe_t;
|
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
// TODO: This class uses O(n) scheduling. Rewrite it to use O(1) algorithm.
|
2012-03-22 11:36:19 -05:00
|
|
|
class router_t :
|
2011-05-23 20:30:01 +02:00
|
|
|
public socket_base_t
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
router_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
|
|
|
|
~router_t ();
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2014-01-08 18:25:31 +01:00
|
|
|
// Overrides of functions from socket_base_t.
|
2013-08-31 09:53:47 -04:00
|
|
|
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
|
2012-03-15 14:57:38 +03:00
|
|
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
2013-05-23 01:49:40 -07:00
|
|
|
int xsend (zmq::msg_t *msg_);
|
|
|
|
int xrecv (zmq::msg_t *msg_);
|
2009-12-13 14:45:23 +01:00
|
|
|
bool xhas_in ();
|
|
|
|
bool xhas_out ();
|
2011-11-09 15:22:20 +01:00
|
|
|
void xread_activated (zmq::pipe_t *pipe_);
|
|
|
|
void xwrite_activated (zmq::pipe_t *pipe_);
|
2013-05-28 16:49:24 +02:00
|
|
|
void xpipe_terminated (zmq::pipe_t *pipe_);
|
2014-05-12 10:40:24 +03:00
|
|
|
|
2011-05-08 09:02:47 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// Rollback any message parts that were sent but not yet flushed.
|
|
|
|
int rollback ();
|
2014-01-12 21:58:36 +01:00
|
|
|
blob_t get_credential () const;
|
2011-05-08 09:02:47 +02:00
|
|
|
|
2010-08-11 14:09:56 +02:00
|
|
|
private:
|
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
// Receive peer id and update lookup map
|
|
|
|
bool identify_peer (pipe_t *pipe_);
|
|
|
|
|
2011-06-22 16:51:40 +02:00
|
|
|
// Fair queueing object for inbound pipes.
|
|
|
|
fq_t fq;
|
2010-04-27 17:36:00 +02:00
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
// True iff there is a message held in the pre-fetch buffer.
|
|
|
|
bool prefetched;
|
|
|
|
|
|
|
|
// If true, the receiver got the message part with
|
|
|
|
// the peer's identity.
|
|
|
|
bool identity_sent;
|
2011-12-17 10:14:32 +01:00
|
|
|
|
|
|
|
// Holds the prefetched identity.
|
2012-04-02 19:51:37 +02:00
|
|
|
msg_t prefetched_id;
|
2010-07-06 22:47:07 +02:00
|
|
|
|
|
|
|
// Holds the prefetched message.
|
2011-04-21 22:27:48 +02:00
|
|
|
msg_t prefetched_msg;
|
2010-07-06 22:47:07 +02:00
|
|
|
|
2015-11-20 21:21:35 +02:00
|
|
|
// The pipe we are currently reading from
|
|
|
|
zmq::pipe_t *current_in;
|
|
|
|
|
|
|
|
// Should current_in should be terminate after all parts received?
|
|
|
|
bool terminate_current_in;
|
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
// If true, more incoming message parts are expected.
|
|
|
|
bool more_in;
|
|
|
|
|
|
|
|
struct outpipe_t
|
|
|
|
{
|
2011-11-09 15:22:20 +01:00
|
|
|
zmq::pipe_t *pipe;
|
2010-04-27 17:36:00 +02:00
|
|
|
bool active;
|
|
|
|
};
|
2009-12-15 09:09:19 +01:00
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
// We keep a set of pipes that have not been identified yet.
|
|
|
|
std::set <pipe_t*> anonymous_pipes;
|
|
|
|
|
2011-06-22 11:02:16 +02:00
|
|
|
// Outbound pipes indexed by the peer IDs.
|
2011-11-04 08:00:47 +01:00
|
|
|
typedef std::map <blob_t, outpipe_t> outpipes_t;
|
2010-02-16 18:30:38 +01:00
|
|
|
outpipes_t outpipes;
|
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
// The pipe we are currently writing to.
|
2011-11-09 15:22:20 +01:00
|
|
|
zmq::pipe_t *current_out;
|
2010-04-27 17:36:00 +02:00
|
|
|
|
|
|
|
// If true, more outgoing message parts are expected.
|
|
|
|
bool more_out;
|
|
|
|
|
2014-01-19 09:27:57 +01:00
|
|
|
// Routing IDs are generated. It's a simple increment and wrap-over
|
2011-06-22 11:02:16 +02:00
|
|
|
// algorithm. This value is the next ID to use (if not used already).
|
2014-01-19 09:27:57 +01:00
|
|
|
uint32_t next_rid;
|
2011-06-22 11:02:16 +02:00
|
|
|
|
2016-04-25 12:18:46 +01:00
|
|
|
// If true, report EAGAIN to the caller instead of silently dropping
|
2012-06-17 02:33:43 +04:00
|
|
|
// the message targeting an unknown peer.
|
2012-10-08 16:36:35 +09:00
|
|
|
bool mandatory;
|
2015-01-23 15:25:40 +01:00
|
|
|
bool raw_socket;
|
2012-03-15 14:57:38 +03:00
|
|
|
|
2013-06-05 15:55:15 +02:00
|
|
|
// if true, send an empty message to every connected router peer
|
|
|
|
bool probe_router;
|
2013-05-21 10:20:24 -07:00
|
|
|
|
2013-10-30 23:45:46 -04:00
|
|
|
// If true, the router will reassign an identity upon encountering a
|
|
|
|
// name collision. The new pipe will take the identity, the old pipe
|
|
|
|
// will be terminated.
|
2013-10-31 23:42:48 -04:00
|
|
|
bool handover;
|
2013-10-30 23:45:46 -04:00
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
router_t (const router_t&);
|
|
|
|
const router_t &operator = (const router_t&);
|
2009-12-13 14:45:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|