Kea 2.7.0
io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2024 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
9
10#include <config.h>
11
12// We want to use coroutine.hpp from the system's boost headers if possible.
13// However, very old Boost versions (provided by RHEL 7 or CentOS 7) didn't have
14// this header. So we can resort to our bundled version, but only if necessary.
15#ifdef HAVE_BOOST_ASIO_COROUTINE_HPP
16#include <boost/asio/coroutine.hpp>
17#else
18#include <ext/coroutine/coroutine.hpp>
19#endif
20
21#include <asiolink/io_address.h>
22#include <asiolink/io_service.h>
23#include <dns/message.h>
24#include <dns/question.h>
25#include <util/buffer.h>
26
27#include <boost/shared_array.hpp>
28#include <boost/shared_ptr.hpp>
29#include <boost/date_time/posix_time/posix_time_types.hpp>
30#include <boost/system/error_code.hpp>
31
32namespace isc {
33namespace asiodns {
34
35// Forward declarations
36struct IOFetchData;
37
41class IOFetch : public boost::asio::coroutine {
42public:
44 enum Protocol {
45 UDP = 0,
46 TCP = 1
47 };
48
53 enum Origin {
54 NONE = 0, // No asynchronous call outstanding
55 OPEN = 1,
56 SEND = 2,
58 CLOSE = 4
59 };
60
66 enum Result {
67 SUCCESS = 0, // Success, fetch completed
68 TIME_OUT = 1, // Failure, fetch timed out
69 STOPPED = 2, // Control code, fetch has been stopped
70 NOTSET = 3 // For testing, indicates value not set
71 };
72
75
77 enum {
78 STAGING_LENGTH = 8192 // Size of staging buffer
79 };
80
93 class Callback {
94 public:
96 Callback() = default;
97
99 virtual ~Callback() = default;
100
106 virtual void operator()(Result result) = 0;
107 };
108
128 IOFetch(Protocol protocol,
129 const isc::asiolink::IOServicePtr& service,
130 const isc::dns::Question& question,
131 const isc::asiolink::IOAddress& address,
132 uint16_t port,
134 Callback* cb,
135 int wait = -1,
136 bool edns = true);
137
158 IOFetch(Protocol protocol,
159 const isc::asiolink::IOServicePtr& service,
160 isc::dns::ConstMessagePtr query_message,
161 const isc::asiolink::IOAddress& address,
162 uint16_t port,
164 Callback* cb,
165 int wait = -1);
166
186 IOFetch(Protocol protocol,
187 const isc::asiolink::IOServicePtr& service,
189 const isc::asiolink::IOAddress& address,
190 uint16_t port,
192 Callback* cb,
193 int wait = -1);
194
198 Protocol getProtocol() const;
199
207 void operator()(boost::system::error_code ec = boost::system::error_code(),
208 size_t length = 0);
209
222 void stop(Result reason = STOPPED);
223
224private:
231 void initIOFetch(isc::dns::MessagePtr& query_message,
232 Protocol protocol,
233 const isc::asiolink::IOServicePtr& service,
234 const isc::dns::Question& question,
235 const isc::asiolink::IOAddress& address,
236 uint16_t port,
238 Callback* cb, int wait,
239 bool edns = true);
240
246 void logIOFailure(boost::system::error_code ec);
247
251 boost::shared_ptr<IOFetchData> data_;
252};
253
255typedef boost::shared_ptr<IOFetch> IOFetchPtr;
256
257} // namespace asiodns
258} // namespace isc
259
260#endif // IO_FETCH_H
I/O Fetch Callback.
Definition io_fetch.h:93
virtual void operator()(Result result)=0
Callback method.
virtual ~Callback()=default
Destructor.
Callback()=default
Constructor.
Upstream Fetch Processing.
Definition io_fetch.h:41
IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr &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:142
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition io_fetch.cc:201
Result
Result of Upstream Fetch.
Definition io_fetch.h:66
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:53
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:44
void stop(Result reason=STOPPED)
Terminate query.
Definition io_fetch.cc:296
Protocol getProtocol() const
Return Current Protocol.
Definition io_fetch.cc:196
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition question.h:88
boost::shared_ptr< IOFetch > IOFetchPtr
Defines a pointer to an IOFetch.
Definition io_fetch.h:255
boost::shared_ptr< const Message > ConstMessagePtr
Definition message.h:671
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition message.h:670
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Definition buffer.h:571
Defines the logger used by the top-level component of kea-lfc.