iofetch.h 3.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15
16
#ifndef __IOFETCH_H
#define __IOFETCH_H 1
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <config.h>

#include <asio.hpp>
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>

#include <dns/buffer.h>
#include <dns/message.h>
#include <dns/messagerenderer.h>

#include <asiolink/asiolink.h>
#include <asiolink/internal/coroutine.h>

// This file contains UDP-specific implementations of generic classes 
// defined in asiolink.h.  It is *not* intended to be part of the public
// API.

namespace asiolink {
//
// Asynchronous UDP coroutine for upstream queries
//
39
class IOFetch : public coroutine {
40
public:
41
    // TODO Maybe this should be more generic than just for IOFetch?
42
43
44
45
46
47
48
49
50
51
52
    ///
    /// \brief Result of the query
    ///
    /// This is related only to contacting the remote server. If the answer
    ///indicates error, it is still counted as SUCCESS here, if it comes back.
    ///
    enum Result {
        SUCCESS,
        TIME_OUT,
        STOPPED
    };
53
    /// Abstract callback for the IOFetch.
54
55
56
57
    class Callback {
    public:
        virtual ~Callback() {}

58
        /// This will be called when the IOFetch is completed
59
60
61
62
63
64
65
66
67
68
        virtual void operator()(Result result) = 0;
    };
    ///
    /// \brief Constructor.
    ///
    /// It creates the query.
    /// @param callback will be called when we terminate. It is your task to
    ///        delete it if allocated on heap.
    ///@param timeout in ms.
    ///
69
    explicit IOFetch(asio::io_service& io_service,
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
                      const isc::dns::Question& q,
                      const IOAddress& addr, uint16_t port,
                      isc::dns::OutputBufferPtr buffer,
                      Callback* callback, int timeout = -1);
    void operator()(asio::error_code ec = asio::error_code(),
                    size_t length = 0);
    /// Terminate the query.
    void stop(Result reason = STOPPED);
private:
    enum { MAX_LENGTH = 4096 };

    ///
    /// \short Private data
    ///
    /// They are not private because of stability of the
    /// interface (this is private class anyway), but because this class
    /// will be copyed often (it is used as a coroutine and passed as callback
    /// to many async_*() functions) and we want keep the same data. Some of
    /// the data is not copyable too.
    ///
    struct PrivateData;
    boost::shared_ptr<PrivateData> data_;
};
}


96
#endif // __IOFETCH_H
97
98
99
100

// Local Variables: 
// mode: c++
// End: