Kea 3.1.3
io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2025 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 <boost/asio/coroutine.hpp>
19#include <boost/asio/deadline_timer.hpp>
20#include <boost/shared_array.hpp>
21#include <boost/shared_ptr.hpp>
22#include <boost/date_time/posix_time/posix_time_types.hpp>
23#include <boost/system/error_code.hpp>
24
25namespace isc {
26namespace asiodns {
27
28// Forward declarations
29struct IOFetchData;
30
34class IOFetch : public boost::asio::coroutine {
35public:
37 enum Protocol {
38 UDP = 0,
39 TCP = 1
40 };
41
46 enum Origin {
47 NONE = 0, // No asynchronous call outstanding
48 OPEN = 1,
49 SEND = 2,
52 };
53
59 enum Result {
60 SUCCESS = 0, // Success, fetch completed
61 TIME_OUT = 1, // Failure, fetch timed out
62 STOPPED = 2, // Control code, fetch has been stopped
63 NOTSET = 3 // For testing, indicates value not set
64 };
65
68
70 enum {
71 STAGING_LENGTH = 8192 // Size of staging buffer
72 };
73
86 class Callback {
87 public:
89 Callback() = default;
90
92 virtual ~Callback() = default;
93
99 virtual void operator()(Result result) = 0;
100 };
101
121 IOFetch(Protocol protocol,
122 const isc::asiolink::IOServicePtr& service,
123 const isc::dns::Question& question,
124 const isc::asiolink::IOAddress& address,
125 uint16_t port,
127 Callback* cb,
128 int wait = -1,
129 bool edns = true);
130
151 IOFetch(Protocol protocol,
152 const isc::asiolink::IOServicePtr& service,
153 isc::dns::ConstMessagePtr query_message,
154 const isc::asiolink::IOAddress& address,
155 uint16_t port,
157 Callback* cb,
158 int wait = -1);
159
179 IOFetch(Protocol protocol,
180 const isc::asiolink::IOServicePtr& service,
182 const isc::asiolink::IOAddress& address,
183 uint16_t port,
185 Callback* cb,
186 int wait = -1);
187
191 Protocol getProtocol() const;
192
200 void operator()(boost::system::error_code ec = boost::system::error_code(),
201 size_t length = 0);
202
215 void stop(Result reason = STOPPED);
216
217private:
224 void initIOFetch(isc::dns::MessagePtr& query_message,
225 Protocol protocol,
226 const isc::asiolink::IOServicePtr& service,
227 const isc::dns::Question& question,
228 const isc::asiolink::IOAddress& address,
229 uint16_t port,
231 Callback* cb, int wait,
232 bool edns = true);
233
239 void logIOFailure(boost::system::error_code ec);
240
244 boost::shared_ptr<IOFetchData> data_;
245};
246
248typedef boost::shared_ptr<IOFetch> IOFetchPtr;
249
250} // namespace asiodns
251} // namespace isc
252
253#endif // IO_FETCH_H
I/O Fetch Callback.
Definition io_fetch.h:86
virtual void operator()(Result result)=0
Callback method.
virtual ~Callback()=default
Destructor.
Callback()=default
Constructor.
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:59
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:46
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:37
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:248
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:574
Defines the logger used by the top-level component of kea-lfc.