Kea 2.7.8
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/shared_array.hpp>
20#include <boost/shared_ptr.hpp>
21#include <boost/date_time/posix_time/posix_time_types.hpp>
22#include <boost/system/error_code.hpp>
23
24namespace isc {
25namespace asiodns {
26
27// Forward declarations
28struct IOFetchData;
29
33class IOFetch : public boost::asio::coroutine {
34public:
36 enum Protocol {
37 UDP = 0,
38 TCP = 1
39 };
40
45 enum Origin {
46 NONE = 0, // No asynchronous call outstanding
47 OPEN = 1,
48 SEND = 2,
50 CLOSE = 4
51 };
52
58 enum Result {
59 SUCCESS = 0, // Success, fetch completed
60 TIME_OUT = 1, // Failure, fetch timed out
61 STOPPED = 2, // Control code, fetch has been stopped
62 NOTSET = 3 // For testing, indicates value not set
63 };
64
67
69 enum {
70 STAGING_LENGTH = 8192 // Size of staging buffer
71 };
72
85 class Callback {
86 public:
88 Callback() = default;
89
91 virtual ~Callback() = default;
92
98 virtual void operator()(Result result) = 0;
99 };
100
120 IOFetch(Protocol protocol,
121 const isc::asiolink::IOServicePtr& service,
122 const isc::dns::Question& question,
123 const isc::asiolink::IOAddress& address,
124 uint16_t port,
126 Callback* cb,
127 int wait = -1,
128 bool edns = true);
129
150 IOFetch(Protocol protocol,
151 const isc::asiolink::IOServicePtr& service,
152 isc::dns::ConstMessagePtr query_message,
153 const isc::asiolink::IOAddress& address,
154 uint16_t port,
156 Callback* cb,
157 int wait = -1);
158
178 IOFetch(Protocol protocol,
179 const isc::asiolink::IOServicePtr& service,
181 const isc::asiolink::IOAddress& address,
182 uint16_t port,
184 Callback* cb,
185 int wait = -1);
186
190 Protocol getProtocol() const;
191
199 void operator()(boost::system::error_code ec = boost::system::error_code(),
200 size_t length = 0);
201
214 void stop(Result reason = STOPPED);
215
216private:
223 void initIOFetch(isc::dns::MessagePtr& query_message,
224 Protocol protocol,
225 const isc::asiolink::IOServicePtr& service,
226 const isc::dns::Question& question,
227 const isc::asiolink::IOAddress& address,
228 uint16_t port,
230 Callback* cb, int wait,
231 bool edns = true);
232
238 void logIOFailure(boost::system::error_code ec);
239
243 boost::shared_ptr<IOFetchData> data_;
244};
245
247typedef boost::shared_ptr<IOFetch> IOFetchPtr;
248
249} // namespace asiodns
250} // namespace isc
251
252#endif // IO_FETCH_H
I/O Fetch Callback.
Definition io_fetch.h:85
virtual void operator()(Result result)=0
Callback method.
virtual ~Callback()=default
Destructor.
Callback()=default
Constructor.
Upstream Fetch Processing.
Definition io_fetch.h:33
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:58
Origin
Origin of Asynchronous I/O Call.
Definition io_fetch.h:45
Protocol
Protocol to use on the fetch.
Definition io_fetch.h:36
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:247
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.