libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
stream.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_STREAM_HPP_INCLUDED__
31 #define __ZMQ_STREAM_HPP_INCLUDED__
32 
33 #include <map>
34 
35 #include "router.hpp"
36 
37 namespace zmq
38 {
39 
40  class ctx_t;
41  class pipe_t;
42 
43  class stream_t :
44  public socket_base_t
45  {
46  public:
47 
48  stream_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
49  ~stream_t ();
50 
51  // Overrides of functions from socket_base_t.
52  void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
53  int xsend (zmq::msg_t *msg_);
54  int xrecv (zmq::msg_t *msg_);
55  bool xhas_in ();
56  bool xhas_out ();
57  void xread_activated (zmq::pipe_t *pipe_);
58  void xwrite_activated (zmq::pipe_t *pipe_);
59  void xpipe_terminated (zmq::pipe_t *pipe_);
60  int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
61  private:
62  // Generate peer's id and update lookup map
63  void identify_peer (pipe_t *pipe_);
64 
65  // Fair queueing object for inbound pipes.
67 
68  // True iff there is a message held in the pre-fetch buffer.
69  bool prefetched;
70 
71  // If true, the receiver got the message part with
72  // the peer's identity.
74 
75  // Holds the prefetched identity.
77 
78  // Holds the prefetched message.
80 
81  struct outpipe_t
82  {
84  bool active;
85  };
86 
87  // Outbound pipes indexed by the peer IDs.
88  typedef std::map <blob_t, outpipe_t> outpipes_t;
89  outpipes_t outpipes;
90 
91  // The pipe we are currently writing to.
93 
94  // If true, more outgoing message parts are expected.
95  bool more_out;
96 
97  // Routing IDs are generated. It's a simple increment and wrap-over
98  // algorithm. This value is the next ID to use (if not used already).
99  uint32_t next_rid;
100 
101  stream_t (const stream_t&);
102  const stream_t &operator = (const stream_t&);
103  };
104 
105 }
106 
107 #endif
outpipes_t outpipes
Definition: stream.hpp:89
const stream_t & operator=(const stream_t &)
bool xhas_out()
Definition: stream.cpp:288
void identify_peer(pipe_t *pipe_)
Definition: stream.cpp:296
stream_t(zmq::ctx_t *parent_, uint32_t tid_, int sid)
Definition: stream.cpp:39
void xpipe_terminated(zmq::pipe_t *pipe_)
Definition: stream.cpp:71
int xsetsockopt(int option_, const void *optval_, size_t optvallen_)
Definition: stream.cpp:178
msg_t prefetched_msg
Definition: stream.hpp:79
zmq::pipe_t * pipe
Definition: stream.hpp:83
int xrecv(zmq::msg_t *msg_)
Definition: stream.cpp:207
int xsend(zmq::msg_t *msg_)
Definition: stream.cpp:98
void xwrite_activated(zmq::pipe_t *pipe_)
Definition: stream.cpp:86
zmq::pipe_t * current_out
Definition: stream.hpp:92
void xattach_pipe(zmq::pipe_t *pipe_, bool subscribe_to_all_)
Definition: stream.cpp:61
std::map< blob_t, outpipe_t > outpipes_t
Definition: stream.hpp:88
bool prefetched
Definition: stream.hpp:69
bool identity_sent
Definition: stream.hpp:73
msg_t prefetched_id
Definition: stream.hpp:76
bool more_out
Definition: stream.hpp:95
Definition: address.hpp:35
Definition: fq.hpp:45
bool xhas_in()
Definition: stream.cpp:254
uint32_t next_rid
Definition: stream.hpp:99
void xread_activated(zmq::pipe_t *pipe_)
Definition: stream.cpp:81