libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
req.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_REQ_HPP_INCLUDED__
31 #define __ZMQ_REQ_HPP_INCLUDED__
32 
33 #include "dealer.hpp"
34 #include "stdint.hpp"
35 
36 namespace zmq
37 {
38 
39  class ctx_t;
40  class msg_t;
41  class io_thread_t;
42  class socket_base_t;
43 
44  class req_t : public dealer_t
45  {
46  public:
47 
48  req_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
49  ~req_t ();
50 
51  // Overrides of functions from socket_base_t.
52  int xsend (zmq::msg_t *msg_);
53  int xrecv (zmq::msg_t *msg_);
54  bool xhas_in ();
55  bool xhas_out ();
56  int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
57  void xpipe_terminated (zmq::pipe_t *pipe_);
58 
59  protected:
60 
61  // Receive only from the pipe the request was sent to, discarding
62  // frames from other pipes.
63  int recv_reply_pipe (zmq::msg_t *msg_);
64 
65  private:
66 
67  // If true, request was already sent and reply wasn't received yet or
68  // was received partially.
70 
71  // If true, we are starting to send/recv a message. The first part
72  // of the message must be empty message part (backtrace stack bottom).
74 
75  // The pipe the request was sent to and where the reply is expected.
77 
78  // Whether request id frames shall be sent and expected.
80 
81  // The current request id. It is incremented every time before a new
82  // request is sent.
83  uint32_t request_id;
84 
85  // If false, send() will reset its internal state and terminate the
86  // reply_pipe's connection instead of failing if a previous request is
87  // still pending.
88  bool strict;
89 
90  req_t (const req_t&);
91  const req_t &operator = (const req_t&);
92  };
93 
95  {
96  public:
97 
98  req_session_t (zmq::io_thread_t *io_thread_, bool connect_,
99  zmq::socket_base_t *socket_, const options_t &options_,
100  address_t *addr_);
101  ~req_session_t ();
102 
103  // Overrides of the functions from session_base_t.
104  int push_msg (msg_t *msg_);
105  void reset ();
106 
107  private:
108 
109  enum {
112  body
113  } state;
114 
115  req_session_t (const req_session_t&);
116  const req_session_t &operator = (const req_session_t&);
117  };
118 
119 }
120 
121 #endif
int xsend(zmq::msg_t *msg_)
Definition: req.cpp:64
req_t(zmq::ctx_t *parent_, uint32_t tid_, int sid_)
Definition: req.cpp:48
bool xhas_in()
Definition: req.cpp:202
int xsetsockopt(int option_, const void *optval_, size_t optvallen_)
Definition: req.cpp:220
const req_t & operator=(const req_t &)
bool xhas_out()
Definition: req.cpp:212
void xpipe_terminated(zmq::pipe_t *pipe_)
Definition: req.cpp:249
bool message_begins
Definition: req.hpp:73
uint32_t request_id
Definition: req.hpp:83
bool receiving_reply
Definition: req.hpp:69
~req_t()
Definition: req.cpp:60
bool request_id_frames_enabled
Definition: req.hpp:79
int xrecv(zmq::msg_t *msg_)
Definition: req.cpp:143
int recv_reply_pipe(zmq::msg_t *msg_)
Definition: req.cpp:256
zmq::pipe_t * reply_pipe
Definition: req.hpp:76
Definition: address.hpp:35
bool strict
Definition: req.hpp:88