Kea: io_fetch.h Source File

| Kea 1.5.0

io_fetch.h
Go to the documentation of this file.
1// Copyright (C) 2010-2018 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
45 class 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,
61 RECEIVE = 3,
62 CLOSE = 4
63 };
64
70 enum Result {
71 SUCCESS = 0,
72 TIME_OUT = 1,
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:
101 Callback()
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,
188 isc::util::OutputBufferPtr& outpkt,
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,
221 isc::asiolink::IOService& service, const isc::dns::Question& question,
222 const isc::asiolink::IOAddress& address, uint16_t port,
223 isc::util::OutputBufferPtr& buff, Callback* cb, int wait,
224 bool edns = true);
225
231 void logIOFailure(boost::system::error_code ec);
232
233 // Member variables. All data is in a structure pointed to by a shared
234 // pointer. The IOFetch object is copied a number of times during its
235 // life, and only requiring a pointer to be copied reduces overhead.
236 boost::shared_ptr<IOFetchData> data_;
237
238};
239
240} // namespace asiodns
241} // namespace isc
242
243#endif // IO_FETCH_H
buffer.h
isc::asiodns::IOFetch::Callback
I/O Fetch Callback.
Definition: io_fetch.h:98
isc::asiodns::IOFetch::Callback::Callback
Callback()
Default Constructor.
Definition: io_fetch.h:101
isc::asiodns::IOFetch::Callback::~Callback
virtual ~Callback()
Virtual Destructor.
Definition: io_fetch.h:105
isc::asiodns::IOFetch::Callback::operator()
virtual void operator()(Result result)=0
Callback method.
isc::asiodns::IOFetch
Upstream Fetch Processing.
Definition: io_fetch.h:45
isc::asiodns::IOFetch::operator()
void operator()(boost::system::error_code ec=boost::system::error_code(), size_t length=0)
Coroutine entry point.
Definition: io_fetch.cc:231
isc::asiodns::IOFetch::STAGING_LENGTH
@ STAGING_LENGTH
Size of staging buffer.
Definition: io_fetch.h:82
isc::asiodns::IOFetch::Result
Result
Result of Upstream Fetch.
Definition: io_fetch.h:70
isc::asiodns::IOFetch::NOTSET
@ NOTSET
For testing, indicates value not set.
Definition: io_fetch.h:74
isc::asiodns::IOFetch::STOPPED
@ STOPPED
Control code, fetch has been stopped.
Definition: io_fetch.h:73
isc::asiodns::IOFetch::TIME_OUT
@ TIME_OUT
Failure, fetch timed out.
Definition: io_fetch.h:72
isc::asiodns::IOFetch::SUCCESS
@ SUCCESS
Success, fetch completed.
Definition: io_fetch.h:71
isc::asiodns::IOFetch::Origin
Origin
Origin of Asynchronous I/O Call.
Definition: io_fetch.h:57
isc::asiodns::IOFetch::SEND
@ SEND
Definition: io_fetch.h:60
isc::asiodns::IOFetch::RECEIVE
@ RECEIVE
Definition: io_fetch.h:61
isc::asiodns::IOFetch::OPEN
@ OPEN
Definition: io_fetch.h:59
isc::asiodns::IOFetch::CLOSE
@ CLOSE
Definition: io_fetch.h:62
isc::asiodns::IOFetch::NONE
@ NONE
No asynchronous call outstanding.
Definition: io_fetch.h:58
isc::asiodns::IOFetch::Protocol
Protocol
Protocol to use on the fetch.
Definition: io_fetch.h:48
isc::asiodns::IOFetch::TCP
@ TCP
Definition: io_fetch.h:50
isc::asiodns::IOFetch::UDP
@ UDP
Definition: io_fetch.h:49
isc::asiodns::IOFetch::stop
void stop(Result reason=STOPPED)
Terminate query.
Definition: io_fetch.cc:334
isc::asiodns::IOFetch::getProtocol
Protocol getProtocol() const
Return Current Protocol.
Definition: io_fetch.cc:223
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic)
Definition: io_address.h:45
isc::asiolink::IOService
The IOService class is a wrapper for the ASIO io_service class.
Definition: io_service.h:31
isc::dns::Question
The Question class encapsulates the common search key of DNS lookup, consisting of owner name,...
Definition: question.h:95
io_address.h
io_service.h
message.h
isc::dns::ConstMessagePtr
boost::shared_ptr< const Message > ConstMessagePtr
Definition: message.h:663
isc::dns::MessagePtr
boost::shared_ptr< Message > MessagePtr
Pointer-like type pointing to a Message.
Definition: message.h:662
isc::util::OutputBufferPtr
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Definition: buffer.h:596
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
question.h