Kea 2.2.0
io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2021 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
33namespace isc {
34namespace asiodns {
35
36// Forward declarations
37struct IOFetchData;
38
44
45class IOFetch : public boost::asio::coroutine {
46public:
48 enum Protocol {
49 UDP = 0,
50 TCP = 1
51 };
52
57 enum Origin {
58 NONE = 0,
59 OPEN = 1,
60 SEND = 2,
62 CLOSE = 4
63 };
64
70 enum Result {
71 SUCCESS = 0,
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 {
82 STAGING_LENGTH = 8192
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
215private:
220 void initIOFetch(isc::dns::MessagePtr& query_message, Protocol protocol,
222 const isc::dns::Question& question,
223 const isc::asiolink::IOAddress& address, uint16_t port,
224 isc::util::OutputBufferPtr& buff, Callback* cb, int wait,
225 bool edns = true);
226
232 void logIOFailure(boost::system::error_code ec);
233
234 // Member variables. All data is in a structure pointed to by a shared
235 // pointer. The IOFetch object is copied a number of times during its
236 // life, and only requiring a pointer to be copied reduces overhead.
237 boost::shared_ptr<IOFetchData> data_;
238};
239
241typedef boost::shared_ptr<IOFetch> IOFetchPtr;
242
243} // namespace asiodns
244} // namespace isc
245
246#endif // IO_FETCH_H
I/O Fetch Callback.
Definition: io_fetch.h:98
Callback()
Default Constructor.
Definition: io_fetch.h:101
virtual ~Callback()
Virtual Destructor.
Definition: io_fetch.h:105
virtual void operator()(Result result)=0
Callback method.
Upstream Fetch Processing.
Definition: io_fetch.h:45
@ STAGING_LENGTH
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:224
Result
Result of Upstream Fetch.
Definition: io_fetch.h:70
@ NOTSET
For testing, indicates value not set.
Definition: io_fetch.h:74
@ STOPPED
Control code, fetch has been stopped.
Definition: io_fetch.h:73
@ TIME_OUT
Failure, fetch timed out.
Definition: io_fetch.h:72
@ SUCCESS
Success, fetch completed.
Definition: io_fetch.h:71
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:154
Origin
Origin of Asynchronous I/O Call.
Definition: io_fetch.h:57
@ NONE
No asynchronous call outstanding.
Definition: io_fetch.h:58
Protocol
Protocol to use on the fetch.
Definition: io_fetch.h:48
void stop(Result reason=STOPPED)
Terminate query.
Definition: io_fetch.cc:326
Protocol getProtocol() const
Return Current Protocol.
Definition: io_fetch.cc:216
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition: question.h:95
boost::shared_ptr< IOFetch > IOFetchPtr
Defines a pointer to an IOFetch.
Definition: io_fetch.h:241
boost::shared_ptr< const Message > ConstMessagePtr
Definition: message.h:663
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition: message.h:662
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Definition: buffer.h:603
Defines the logger used by the top-level component of kea-lfc.