Kea 3.3.3
io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2026 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#include <asiolink/io_address.h>
13#include <asiolink/io_service.h>
14#include <dns/message.h>
15#include <dns/question.h>
16#include <util/buffer.h>
17
18#include <cstdint>
19
20#include <boost/asio/coroutine.hpp>
21#include <boost/asio/system_timer.hpp>
22#include <boost/date_time/posix_time/posix_time_types.hpp>
23#include <boost/shared_array.hpp>
24#include <boost/shared_ptr.hpp>
25#include <boost/system/error_code.hpp>
26
27namespace isc {
28namespace asiodns {
29
30// Forward declarations
31struct IOFetchData;
32
36class IOFetch : public boost::asio::coroutine {
37public:
39 enum Protocol : uint16_t {
40 UDP = 0,
41 TCP = 1
42 };
43
48 enum Origin : uint16_t {
49 NONE = 0, // No asynchronous call outstanding
50 OPEN = 1,
51 SEND = 2,
54 };
55
61 enum Result : uint16_t {
62 SUCCESS = 0, // Success, fetch completed
63 TIME_OUT = 1, // Failure, fetch timed out
64 STOPPED = 2, // Control code, fetch has been stopped
65 IO_ERROR = 3, // Failure, asynchronous I/O returned an error
66 NOTSET = 4 // For testing, indicates value not set
67 };
68
74 static std::string const& resultToText(Result const& result) {
75 static std::vector<std::string> const text_vector {
76 "SUCCESS",
77 "TIME_OUT",
78 "STOPPED",
79 "IO_ERROR",
80 "NOTSET",
81 };
82 static std::string const unknown("UNKNOWN");
83 return (result < text_vector.size() ? text_vector[result] : unknown);
84 }
85
88
90 enum {
91 STAGING_LENGTH = 8192 // Size of staging buffer
92 };
93
106 class Callback {
107 public:
109 Callback() = default;
110
112 virtual ~Callback() = default;
113
119 virtual void operator()(Result result) = 0;
120 };
121
141 IOFetch(Protocol protocol,
142 const isc::asiolink::IOServicePtr& service,
143 const isc::dns::Question& question,
144 const isc::asiolink::IOAddress& address,
145 uint16_t port,
147 Callback* cb,
148 int wait = -1,
149 bool edns = true);
150
171 IOFetch(Protocol protocol,
172 const isc::asiolink::IOServicePtr& service,
173 isc::dns::ConstMessagePtr query_message,
174 const isc::asiolink::IOAddress& address,
175 uint16_t port,
177 Callback* cb,
178 int wait = -1);
179
199 IOFetch(Protocol protocol,
200 const isc::asiolink::IOServicePtr& service,
202 const isc::asiolink::IOAddress& address,
203 uint16_t port,
205 Callback* cb,
206 int wait = -1);
207
211 Protocol getProtocol() const;
212
220 void operator()(boost::system::error_code ec = boost::system::error_code(),
221 size_t length = 0);
222
235 void stop(Result reason = STOPPED);
236
237private:
244 void initIOFetch(isc::dns::MessagePtr& query_message,
245 Protocol protocol,
246 const isc::asiolink::IOServicePtr& service,
247 const isc::dns::Question& question,
248 const isc::asiolink::IOAddress& address,
249 uint16_t port,
251 Callback* cb, int wait,
252 bool edns = true);
253
259 void logIOFailure(boost::system::error_code ec);
260
264 boost::shared_ptr<IOFetchData> data_;
265};
266
268typedef boost::shared_ptr<IOFetch> IOFetchPtr;
269
270} // namespace asiodns
271} // namespace isc
272
273#endif // IO_FETCH_H
I/O Fetch Callback.
Definition io_fetch.h:106
virtual void operator()(Result result)=0
Callback method.
virtual ~Callback()=default
Destructor.
Callback()=default
Constructor.
static std::string const & resultToText(Result const &result)
Convert enum to string.
Definition io_fetch.h:74
Result
Result of Upstream Fetch.
Definition io_fetch.h:61
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:48
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:39
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:143
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition io_fetch.cc:202
void stop(Result reason=STOPPED)
Terminate query.
Definition io_fetch.cc:304
Protocol getProtocol() const
Return Current Protocol.
Definition io_fetch.cc:197
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:268
boost::shared_ptr< const Message > ConstMessagePtr
Definition message.h:669
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition message.h:668
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Definition buffer.h:583
Defines the logger used by the top-level component of kea-lfc.