Kea  1.9.9-git
io_fetch.h
Go to the documentation of this file.
1 // Copyright (C) 2010-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef IO_FETCH_H
8 #define IO_FETCH_H 1
9 
10 #include <config.h>
11 
12 #include <boost/shared_array.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/date_time/posix_time/posix_time_types.hpp>
15 
16 // We want to use coroutine.hpp from the system's boost headers if possible.
17 // However, very old Boost versions (provided by RHEL 7 or CentOS 7) didn't have
18 // this header. So we can resort to our bundled version, but only if necessary.
19 #ifdef HAVE_BOOST_ASIO_COROUTINE_HPP
20 #include <boost/asio/coroutine.hpp>
21 #else
22 #include <ext/coroutine/coroutine.hpp>
23 #endif
24 
25 #include <boost/system/error_code.hpp>
26 #include <asiolink/io_address.h>
27 #include <asiolink/io_service.h>
28 
29 #include <util/buffer.h>
30 #include <dns/question.h>
31 #include <dns/message.h>
32 
33 namespace isc {
34 namespace asiodns {
35 
36 // Forward declarations
37 struct IOFetchData;
38 
44 
45 class IOFetch : public boost::asio::coroutine {
46 public:
48  enum Protocol {
49  UDP = 0,
50  TCP = 1
51  };
52 
57  enum Origin {
58  NONE = 0,
59  OPEN = 1,
60  SEND = 2,
61  RECEIVE = 3,
62  CLOSE = 4
63  };
64 
70  enum Result {
71  SUCCESS = 0,
72  TIME_OUT = 1,
73  STOPPED = 2,
74  NOTSET = 3
75  };
76 
77  // The next enum is a "trick" to allow constants to be defined in a class
78  // declaration.
79 
81  enum {
83  };
84 
98  class Callback {
99  public:
102  {}
103 
105  virtual ~Callback()
106  {}
107 
113  virtual void operator()(Result result) = 0;
114  };
115 
135  IOFetch(Protocol protocol, isc::asiolink::IOService& service,
136  const isc::dns::Question& question,
137  const isc::asiolink::IOAddress& address,
138  uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
139  int wait = -1,
140  bool edns = true);
141 
162  IOFetch(Protocol protocol, isc::asiolink::IOService& service,
163  isc::dns::ConstMessagePtr query_message,
164  const isc::asiolink::IOAddress& address,
165  uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
166  int wait = -1);
167 
187  IOFetch(Protocol protocol, isc::asiolink::IOService& service,
189  const isc::asiolink::IOAddress& address,
190  uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
191  int wait = -1);
192 
196  Protocol getProtocol() const;
197 
205  void operator()(boost::system::error_code ec = boost::system::error_code(), size_t length = 0);
206 
213  void stop(Result reason = STOPPED);
214 
215 private:
220  void initIOFetch(isc::dns::MessagePtr& query_message, Protocol protocol,
221  isc::asiolink::IOService& service, const isc::dns::Question& question,
222  const isc::asiolink::IOAddress& address, uint16_t port,
223  isc::util::OutputBufferPtr& buff, Callback* cb, int wait,
224  bool edns = true);
225 
231  void logIOFailure(boost::system::error_code ec);
232 
233  // Member variables. All data is in a structure pointed to by a shared
234  // pointer. The IOFetch object is copied a number of times during its
235  // life, and only requiring a pointer to be copied reduces overhead.
236  boost::shared_ptr<IOFetchData> data_;
237 
238 };
239 
240 } // namespace asiodns
241 } // namespace isc
242 
243 #endif // IO_FETCH_H
Upstream Fetch Processing.
Definition: io_fetch.h:45
void stop(Result reason=STOPPED)
Terminate query.
Definition: io_fetch.cc:334
Control code, fetch has been stopped.
Definition: io_fetch.h:73
Protocol
Protocol to use on the fetch.
Definition: io_fetch.h:48
The Question class encapsulates the common search key of DNS lookup, consisting of owner name...
Definition: question.h:95
Size of staging buffer.
Definition: io_fetch.h:82
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition: io_fetch.cc:231
Failure, fetch timed out.
Definition: io_fetch.h:72
Protocol getProtocol() const
Return Current Protocol.
Definition: io_fetch.cc:223
IOFetch(Protocol protocol, isc::asiolink::IOService &service, const isc::dns::Question &question, const isc::asiolink::IOAddress &address, uint16_t port, isc::util::OutputBufferPtr &buff, Callback *cb, int wait=-1, bool edns=true)
Constructor.
Definition: io_fetch.cc:156
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition: message.h:662
Origin
Origin of Asynchronous I/O Call.
Definition: io_fetch.h:57
virtual void operator()(Result result)=0
Callback method.
For testing, indicates value not set.
Definition: io_fetch.h:74
Callback()
Default Constructor.
Definition: io_fetch.h:101
Defines the logger used by the top-level component of kea-dhcp-ddns.
Result
Result of Upstream Fetch.
Definition: io_fetch.h:70
virtual ~Callback()
Virtual Destructor.
Definition: io_fetch.h:105
No asynchronous call outstanding.
Definition: io_fetch.h:58
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Definition: buffer.h:599
Success, fetch completed.
Definition: io_fetch.h:71
boost::shared_ptr< const Message > ConstMessagePtr
Definition: message.h:663
I/O Fetch Callback.
Definition: io_fetch.h:98