BIND 10 trac751, updated. 8fc7cdd216bead2a98f1c98a6b6dc7a8a3bea4f4 [trac751] Move dns related code to asiodns lib

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Apr 8 09:03:13 UTC 2011


The branch, trac751 has been updated
       via  8fc7cdd216bead2a98f1c98a6b6dc7a8a3bea4f4 (commit)
      from  8fdbc3e46da7c31b4a533bbfe5778bf7d68e1bbe (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8fc7cdd216bead2a98f1c98a6b6dc7a8a3bea4f4
Author: Ocean Wang <wanghaidong at cnnic.cn>
Date:   Fri Apr 8 17:02:44 2011 +0800

    [trac751] Move dns related code to asiodns lib

-----------------------------------------------------------------------

Summary of changes:
 configure.ac                                       |    1 +
 .../asiodns/.deps/libasiodns_la-dns_service.Plo    |    1 -
 src/lib/asiodns/Makefile.am                        |    1 +
 src/lib/asiodns/dns_answer.h                       |   10 +++++++---
 src/lib/asiodns/dns_lookup.h                       |   10 ++++++----
 src/lib/asiodns/dns_server.h                       |    8 +++++---
 src/lib/asiodns/dns_service.cc                     |   17 +++++++++--------
 src/lib/asiodns/dns_service.h                      |   20 +++++++++++---------
 src/lib/{asiolink => asiodns}/io_fetch.cc          |   12 ++++++++----
 src/lib/{asiolink => asiodns}/io_fetch.h           |   15 +++++++++------
 src/lib/asiodns/tcp_server.cc                      |   10 ++++++----
 src/lib/asiodns/tcp_server.h                       |   20 ++++++++++++--------
 src/lib/asiodns/tests/Makefile.am                  |    4 ++++
 src/lib/asiodns/tests/dns_server_unittest.cc       |   11 ++++++-----
 .../tests/io_fetch_unittest.cc                     |    9 ++++++---
 src/lib/asiodns/tests/io_service_unittest.cc       |    4 +++-
 src/lib/asiodns/udp_server.cc                      |    9 ++++++---
 src/lib/asiodns/udp_server.h                       |   14 ++++++++------
 src/lib/asiolink/Makefile.am                       |    1 -
 src/lib/asiolink/asiodef.cc                        |    2 ++
 src/lib/asiolink/asiodef.h                         |    2 ++
 src/lib/asiolink/asiolink_utilities.h              |    2 ++
 src/lib/asiolink/dummy_io_cb.h                     |    2 ++
 src/lib/asiolink/interval_timer.cc                 |    4 +++-
 src/lib/asiolink/interval_timer.h                  |    4 +++-
 src/lib/asiolink/io_address.cc                     |    4 +++-
 src/lib/asiolink/io_address.h                      |    4 +++-
 src/lib/asiolink/io_asio_socket.h                  |    3 ++-
 src/lib/asiolink/io_endpoint.cc                    |    4 +++-
 src/lib/asiolink/io_endpoint.h                     |    4 +++-
 src/lib/asiolink/io_error.h                        |    4 +++-
 src/lib/asiolink/io_message.h                      |    4 +++-
 src/lib/asiolink/io_service.cc                     |    4 +++-
 src/lib/asiolink/io_service.h                      |    4 +++-
 src/lib/asiolink/io_socket.cc                      |    6 +++---
 src/lib/asiolink/io_socket.h                       |    2 ++
 src/lib/asiolink/qid_gen.cc                        |    4 +++-
 src/lib/asiolink/qid_gen.h                         |    2 ++
 src/lib/asiolink/simple_callback.h                 |    4 +++-
 src/lib/asiolink/tcp_endpoint.h                    |    4 +++-
 src/lib/asiolink/tcp_socket.h                      |    2 ++
 src/lib/asiolink/tests/Makefile.am                 |    1 -
 .../asiolink/tests/asiolink_utilities_unittest.cc  |    2 +-
 src/lib/asiolink/tests/interval_timer_unittest.cc  |    2 +-
 src/lib/asiolink/tests/io_address_unittest.cc      |    2 +-
 src/lib/asiolink/tests/io_endpoint_unittest.cc     |    2 +-
 src/lib/asiolink/tests/io_socket_unittest.cc       |    2 +-
 src/lib/asiolink/tests/qid_gen_unittest.cc         |    6 +++---
 src/lib/asiolink/tests/tcp_endpoint_unittest.cc    |    2 +-
 src/lib/asiolink/tests/tcp_socket_unittest.cc      |    2 +-
 src/lib/asiolink/tests/udp_endpoint_unittest.cc    |    2 +-
 src/lib/asiolink/tests/udp_socket_unittest.cc      |    2 +-
 src/lib/asiolink/udp_endpoint.h                    |    4 +++-
 src/lib/asiolink/udp_socket.h                      |    2 ++
 54 files changed, 183 insertions(+), 100 deletions(-)
 delete mode 100644 src/lib/asiodns/.deps/libasiodns_la-dns_service.Plo
 delete mode 100644 src/lib/asiodns/.deps/libasiodns_la-dns_service.Tpo
 rename src/lib/{asiolink => asiodns}/io_fetch.cc (98%)
 rename src/lib/{asiolink => asiodns}/io_fetch.h (95%)
 rename src/lib/{asiolink => asiodns}/tests/io_fetch_unittest.cc (99%)

-----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index ee07903..64db689 100644
--- a/configure.ac
+++ b/configure.ac
@@ -643,6 +643,7 @@ AC_CONFIG_FILES([Makefile
                  src/lib/asiolink/Makefile
                  src/lib/asiolink/tests/Makefile
                  src/lib/asiodns/Makefile
+                 src/lib/asiodns/tests/Makefile
                  src/lib/bench/Makefile
                  src/lib/bench/example/Makefile
                  src/lib/bench/tests/Makefile
diff --git a/src/lib/asiodns/.deps/libasiodns_la-dns_service.Plo b/src/lib/asiodns/.deps/libasiodns_la-dns_service.Plo
deleted file mode 100644
index 9ce06a8..0000000
--- a/src/lib/asiodns/.deps/libasiodns_la-dns_service.Plo
+++ /dev/null
@@ -1 +0,0 @@
-# dummy
diff --git a/src/lib/asiodns/.deps/libasiodns_la-dns_service.Tpo b/src/lib/asiodns/.deps/libasiodns_la-dns_service.Tpo
deleted file mode 100644
index e69de29..0000000
diff --git a/src/lib/asiodns/Makefile.am b/src/lib/asiodns/Makefile.am
index e17774d..ef0c32c 100644
--- a/src/lib/asiodns/Makefile.am
+++ b/src/lib/asiodns/Makefile.am
@@ -19,6 +19,7 @@ libasiodns_la_SOURCES += dns_server.h
 libasiodns_la_SOURCES += dns_service.cc dns_service.h
 libasiodns_la_SOURCES += tcp_server.cc tcp_server.h
 libasiodns_la_SOURCES += udp_server.cc udp_server.h
+libasiodns_la_SOURCES += io_fetch.cc io_fetch.h
 
 # Note: the ordering matters: -Wno-... must follow -Wextra (defined in
 # B10_CXXFLAGS)
diff --git a/src/lib/asiodns/dns_answer.h b/src/lib/asiodns/dns_answer.h
index 84e1f6f..f4d643e 100644
--- a/src/lib/asiodns/dns_answer.h
+++ b/src/lib/asiodns/dns_answer.h
@@ -16,8 +16,11 @@
 #define __ASIOLINK_DNS_ANSWER_H 1
 
 #include <asiolink/io_message.h>
+#include <dns/buffer.h>
+#include <dns/message.h>
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /// \brief The \c DNSAnswer class is an abstract base class for a DNS
 /// Answer provider function.
@@ -63,11 +66,12 @@ public:
     /// \param answer_message The DNS MessagePtr of the answer we are
     /// building
     /// \param buffer Intermediate data results are put here
-    virtual void operator()(const IOMessage& io_message,
+    virtual void operator()(const asiolink::IOMessage& io_message,
                             isc::dns::MessagePtr query_message,
                             isc::dns::MessagePtr answer_message,
                             isc::dns::OutputBufferPtr buffer) const = 0;
 };
 
-}      // namespace asiolink
+}      // namespace asiodns
+}      // namespace isc
 #endif // __ASIOLINK_DNS_ANSWER_H
diff --git a/src/lib/asiodns/dns_lookup.h b/src/lib/asiodns/dns_lookup.h
index a79976f..a3b0b36 100644
--- a/src/lib/asiodns/dns_lookup.h
+++ b/src/lib/asiodns/dns_lookup.h
@@ -16,11 +16,12 @@
 #define __ASIOLINK_DNS_LOOKUP_H 1
 
 #include <asiolink/io_message.h>
-#include <asiolink/dns_server.h>
+#include <asiodns/dns_server.h>
 #include <dns/buffer.h>
 #include <dns/message.h>
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /// \brief The \c DNSLookup class is an abstract base class for a DNS
 /// Lookup provider function.
@@ -67,7 +68,7 @@ public:
     ///                       this MessagePtr
     /// \param buffer The final answer is put here
     /// \param server DNSServer object to use
-    virtual void operator()(const IOMessage& io_message,
+    virtual void operator()(const asiolink::IOMessage& io_message,
                             isc::dns::MessagePtr message,
                             isc::dns::MessagePtr answer_message,
                             isc::dns::OutputBufferPtr buffer,
@@ -79,5 +80,6 @@ private:
     DNSLookup* self_;
 };
 
-}      // namespace asiolink
+}      // namespace asiodns
+}      // namespace isc
 #endif // __ASIOLINK_DNS_LOOKUP_H
diff --git a/src/lib/asiodns/dns_server.h b/src/lib/asiodns/dns_server.h
index f15f808..f235860 100644
--- a/src/lib/asiodns/dns_server.h
+++ b/src/lib/asiodns/dns_server.h
@@ -17,7 +17,8 @@
 
 #include <asiolink/io_message.h>
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /// \brief The \c DNSServer class is a wrapper (and base class) for
 /// classes which provide DNS server functionality.
@@ -34,7 +35,7 @@ namespace asiolink {
 /// instantiated through a base class) are sometimes passed by
 /// reference (as this superclass); calls to methods in the base
 /// class are then rerouted via this pointer to methods in the derived
-/// class.  This allows code from outside asiolink, with no specific
+/// class.  This allows code from outside asiodns, with no specific
 /// knowledge of \c TCPServer or \c UDPServer, to access their methods.
 ///
 /// This class is both assignable and copy-constructable.  Its subclasses
@@ -151,5 +152,6 @@ private:
 };
 
 
-}      // asiolink
+} // namespace asiodns
+} // namespace isc
 #endif // __ASIOLINK_DNS_SERVER_H
diff --git a/src/lib/asiodns/dns_service.cc b/src/lib/asiodns/dns_service.cc
index f17bb44..94510fe 100644
--- a/src/lib/asiodns/dns_service.cc
+++ b/src/lib/asiodns/dns_service.cc
@@ -23,11 +23,11 @@
 #include <log/dummylog.h>
 
 #include <asio.hpp>
-#include <asiolink/dns_service.h>
+#include <dns_service.h>
 #include <asiolink/io_service.h>
 #include <asiolink/io_service.h>
-#include <asiolink/tcp_server.h>
-#include <asiolink/udp_server.h>
+#include <tcp_server.h>
+#include <udp_server.h>
 
 #include <log/dummylog.h>
 
@@ -36,9 +36,11 @@
 
 using isc::log::dlog;
 
-namespace asiolink {
+using namespace isc::asiolink;
+
+namespace isc {
+namespace asiodns {
 
-class SimpleCallback;
 class DNSLookup;
 class DNSAnswer;
 
@@ -195,6 +197,5 @@ DNSService::clearServers() {
     impl_->servers_.clear();
 }
 
-
-
-} // namespace asiolink
+} // namespace asiodns
+} // namespace isc
diff --git a/src/lib/asiodns/dns_service.h b/src/lib/asiodns/dns_service.h
index 9a3fb4c..6b6a6c0 100644
--- a/src/lib/asiodns/dns_service.h
+++ b/src/lib/asiodns/dns_service.h
@@ -18,10 +18,11 @@
 #include <resolve/resolver_interface.h>
 
 #include <asiolink/io_service.h>
+#include <asiolink/simple_callback.h>
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
-class SimpleCallback;
 class DNSLookup;
 class DNSAnswer;
 class DNSServiceImpl;
@@ -54,8 +55,8 @@ public:
     /// \param checkin Provider for cc-channel events (see \c SimpleCallback)
     /// \param lookup The lookup provider (see \c DNSLookup)
     /// \param answer The answer provider (see \c DNSAnswer)
-    DNSService(IOService& io_service, const char& port,
-               const char& address, SimpleCallback* checkin,
+    DNSService(asiolink::IOService& io_service, const char& port,
+               const char& address, isc::asiolink::SimpleCallback* checkin,
                DNSLookup* lookup, DNSAnswer* answer);
     /// \brief The constructor with a specific port on which the services
     /// listen on.
@@ -71,14 +72,14 @@ public:
     /// \param checkin Provider for cc-channel events (see \c SimpleCallback)
     /// \param lookup The lookup provider (see \c DNSLookup)
     /// \param answer The answer provider (see \c DNSAnswer)
-    DNSService(IOService& io_service, const char& port,
+    DNSService(asiolink::IOService& io_service, const char& port,
                const bool use_ipv4, const bool use_ipv6,
-               SimpleCallback* checkin, DNSLookup* lookup,
+               isc::asiolink::SimpleCallback* checkin, DNSLookup* lookup,
                DNSAnswer* answer);
     /// \brief The constructor without any servers.
     ///
     /// Use addServer() to add some servers.
-    DNSService(IOService& io_service, SimpleCallback* checkin,
+    DNSService(asiolink::IOService& io_service, isc::asiolink::SimpleCallback* checkin,
                DNSLookup* lookup, DNSAnswer* answer);
     /// \brief The destructor.
     ~DNSService();
@@ -105,8 +106,9 @@ public:
 
 private:
     DNSServiceImpl* impl_;
-    IOService& io_service_;
+    asiolink::IOService& io_service_;
 };
 
-}      // namespace asiolink
+} // namespace asiodns
+} // namespace isc
 #endif // __ASIOLINK_DNS_SERVICE_H
diff --git a/src/lib/asiodns/io_fetch.cc b/src/lib/asiodns/io_fetch.cc
new file mode 100644
index 0000000..a51d115
--- /dev/null
+++ b/src/lib/asiodns/io_fetch.cc
@@ -0,0 +1,384 @@
+// Copyright (C) 2011  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.
+
+#include <config.h>
+
+#include <unistd.h>             // for some IPC/network system calls
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <boost/bind.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+#include <dns/message.h>
+#include <dns/messagerenderer.h>
+#include <dns/opcode.h>
+#include <dns/rcode.h>
+#include <log/logger.h>
+
+#include <asiolink/qid_gen.h>
+
+#include <asio.hpp>
+#include <asio/deadline_timer.hpp>
+
+#include <asiolink/asiodef.h>
+#include <asiolink/io_address.h>
+#include <asiolink/io_asio_socket.h>
+#include <asiolink/io_endpoint.h>
+#include <asiolink/io_service.h>
+#include <asiolink/tcp_endpoint.h>
+#include <asiolink/tcp_socket.h>
+#include <asiolink/udp_endpoint.h>
+#include <asiolink/udp_socket.h>
+#include <asiolink/qid_gen.h>
+
+#include "io_fetch.h"
+
+#include <stdint.h>
+
+using namespace asio;
+using namespace isc::asiolink;
+using namespace isc::dns;
+using namespace isc::log;
+using namespace std;
+
+namespace isc {
+namespace asiodns {
+
+/// Use the ASIO logger
+
+isc::log::Logger logger("asiodns");
+
+/// \brief IOFetch Data
+///
+/// The data for IOFetch is held in a separate struct pointed to by a shared_ptr
+/// object.  This is because the IOFetch object will be copied often (it is used
+/// as a coroutine and passed as callback to many async_*() functions) and we
+/// want keep the same data).  Organising the data in this way keeps copying to
+/// a minimum.
+struct IOFetchData {
+
+    // The first two members are shared pointers to a base class because what is
+    // actually instantiated depends on whether the fetch is over UDP or TCP,
+    // which is not known until construction of the IOFetch.  Use of a shared
+    // pointer here is merely to ensure deletion when the data object is deleted.
+    boost::scoped_ptr<IOAsioSocket<IOFetch> > socket;
+                                             ///< Socket to use for I/O
+    boost::scoped_ptr<IOEndpoint> remote_snd;///< Where the fetch is sent
+    boost::scoped_ptr<IOEndpoint> remote_rcv;///< Where the response came from
+    isc::dns::Question          question;    ///< Question to be asked
+    isc::dns::OutputBufferPtr   msgbuf;      ///< Wire buffer for question
+    isc::dns::OutputBufferPtr   received;    ///< Received data put here
+    IOFetch::Callback*          callback;    ///< Called on I/O Completion
+    asio::deadline_timer        timer;       ///< Timer to measure timeouts
+    IOFetch::Protocol           protocol;    ///< Protocol being used
+    size_t                      cumulative;  ///< Cumulative received amount
+    size_t                      expected;    ///< Expected amount of data
+    size_t                      offset;      ///< Offset to receive data
+    bool                        stopped;     ///< Have we stopped running?
+    int                         timeout;     ///< Timeout in ms
+
+    // In case we need to log an error, the origin of the last asynchronous
+    // I/O is recorded.  To save time and simplify the code, this is recorded
+    // as the ID of the error message that would be generated if the I/O failed.
+    // This means that we must make sure that all possible "origins" take the
+    // same arguments in their message in the same order.
+    isc::log::MessageID         origin;     ///< Origin of last asynchronous I/O
+    uint8_t                     staging[IOFetch::STAGING_LENGTH];
+                                            ///< Temporary array for received data
+    isc::dns::qid_t             qid;         ///< The QID set in the query
+
+    /// \brief Constructor
+    ///
+    /// Just fills in the data members of the IOFetchData structure
+    ///
+    /// \param proto Either IOFetch::TCP or IOFetch::UDP.
+    /// \param service I/O Service object to handle the asynchronous
+    ///        operations.
+    /// \param query DNS question to send to the upstream server.
+    /// \param address IP address of upstream server
+    /// \param port Port to use for the query
+    /// \param buff Output buffer into which the response (in wire format)
+    ///        is written (if a response is received).
+    /// \param cb Callback object containing the callback to be called
+    ///        when we terminate.  The caller is responsible for managing this
+    ///        object and deleting it if necessary.
+    /// \param wait Timeout for the fetch (in ms).
+    ///
+    /// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
+    IOFetchData(IOFetch::Protocol proto, IOService& service,
+        const isc::dns::Question& query, const IOAddress& address,
+        uint16_t port, isc::dns::OutputBufferPtr& buff, IOFetch::Callback* cb,
+        int wait)
+        :
+        socket((proto == IOFetch::UDP) ?
+            static_cast<IOAsioSocket<IOFetch>*>(
+                new UDPSocket<IOFetch>(service)) :
+            static_cast<IOAsioSocket<IOFetch>*>(
+                new TCPSocket<IOFetch>(service))
+            ),
+        remote_snd((proto == IOFetch::UDP) ?
+            static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
+            static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
+            ),
+        remote_rcv((proto == IOFetch::UDP) ?
+            static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
+            static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
+            ),
+        question(query),
+        msgbuf(new isc::dns::OutputBuffer(512)),
+        received(buff),
+
+        callback(cb),
+        timer(service.get_io_service()),
+        protocol(proto),
+        cumulative(0),
+        expected(0),
+        offset(0),
+        stopped(false),
+        timeout(wait),
+        origin(ASIO_UNKORIGIN),
+        staging(),
+        qid(QidGenerator::getInstance().generateQid())
+    {}
+
+    // Checks if the response we received was ok;
+    // - data contains the buffer we read, as well as the address
+    // we sent to and the address we received from.
+    // length is provided by the operator() in IOFetch.
+    // Addresses must match, number of octets read must be at least
+    // 2, and the first two octets must match the qid of the message
+    // we sent.
+    bool responseOK() {
+        return (*remote_snd == *remote_rcv && cumulative >= 2 &&
+                readUint16(received->getData()) == qid);
+    }
+};
+
+/// IOFetch Constructor - just initialize the private data
+
+IOFetch::IOFetch(Protocol protocol, IOService& service,
+    const isc::dns::Question& question, const IOAddress& address, uint16_t port,
+    OutputBufferPtr& buff, Callback* cb, int wait)
+    :
+    data_(new IOFetchData(protocol, service, question, address,
+        port, buff, cb, wait))
+{
+}
+
+// Return protocol in use.
+
+IOFetch::Protocol
+IOFetch::getProtocol() const {
+    return (data_->protocol);
+}
+
+/// The function operator is implemented with the "stackless coroutine"
+/// pattern; see internal/coroutine.h for details.
+
+void
+IOFetch::operator()(asio::error_code ec, size_t length) {
+
+    if (data_->stopped) {
+        return;
+    } else if (ec) {
+        logIOFailure(ec);
+        return;
+    }
+
+    CORO_REENTER (this) {
+
+        /// Generate the upstream query and render it to wire format
+        /// This is done in a different scope to allow inline variable
+        /// declarations.
+        {
+            Message msg(Message::RENDER);
+            msg.setQid(data_->qid);
+            msg.setOpcode(Opcode::QUERY());
+            msg.setRcode(Rcode::NOERROR());
+            msg.setHeaderFlag(Message::HEADERFLAG_RD);
+            msg.addQuestion(data_->question);
+            MessageRenderer renderer(*data_->msgbuf);
+            msg.toWire(renderer);
+        }
+
+        // If we timeout, we stop, which will can cancel outstanding I/Os and
+        // shutdown everything.
+        if (data_->timeout != -1) {
+            data_->timer.expires_from_now(boost::posix_time::milliseconds(
+                data_->timeout));
+            data_->timer.async_wait(boost::bind(&IOFetch::stop, *this,
+                TIME_OUT));
+        }
+
+        // Open a connection to the target system.  For speed, if the operation
+        // is synchronous (i.e. UDP operation) we bypass the yield.
+        data_->origin = ASIO_OPENSOCK;
+        if (data_->socket->isOpenSynchronous()) {
+            data_->socket->open(data_->remote_snd.get(), *this);
+        } else {
+            CORO_YIELD data_->socket->open(data_->remote_snd.get(), *this);
+        }
+
+        do {
+            // Begin an asynchronous send, and then yield.  When the send completes,
+            // we will resume immediately after this point.
+            data_->origin = ASIO_SENDSOCK;
+            CORO_YIELD data_->socket->asyncSend(data_->msgbuf->getData(),
+                data_->msgbuf->getLength(), data_->remote_snd.get(), *this);
+    
+            // Now receive the response.  Since TCP may not receive the entire
+            // message in one operation, we need to loop until we have received
+            // it. (This can't be done within the asyncReceive() method because
+            // each I/O operation will be done asynchronously and between each one
+            // we need to yield ... and we *really* don't want to set up another
+            // coroutine within that method.)  So after each receive (and yield),
+            // we check if the operation is complete and if not, loop to read again.
+            //
+            // Another concession to TCP is that the amount of is contained in the
+            // first two bytes.  This leads to two problems:
+            //
+            // a) We don't want those bytes in the return buffer.
+            // b) They may not both arrive in the first I/O.
+            //
+            // So... we need to loop until we have at least two bytes, then store
+            // the expected amount of data.  Then we need to loop until we have
+            // received all the data before copying it back to the user's buffer.
+            // And we want to minimise the amount of copying...
+    
+            data_->origin = ASIO_RECVSOCK;
+            data_->cumulative = 0;          // No data yet received
+            data_->offset = 0;              // First data into start of buffer
+            data_->received->clear();       // Clear the receive buffer
+            do {
+                CORO_YIELD data_->socket->asyncReceive(data_->staging,
+                                                       static_cast<size_t>(STAGING_LENGTH),
+                                                       data_->offset,
+                                                       data_->remote_rcv.get(), *this);
+            } while (!data_->socket->processReceivedData(data_->staging, length,
+                                                         data_->cumulative, data_->offset,
+                                                         data_->expected, data_->received));
+        } while (!data_->responseOK());
+
+        // Finished with this socket, so close it.  This will not generate an
+        // I/O error, but reset the origin to unknown in case we change this.
+        data_->origin = ASIO_UNKORIGIN;
+        data_->socket->close();
+
+        /// We are done
+        stop(SUCCESS);
+    }
+}
+
+// Function that stops the coroutine sequence.  It is called either when the
+// query finishes or when the timer times out.  Either way, it sets the
+// "stopped_" flag and cancels anything that is in progress.
+//
+// As the function may be entered multiple times as things wind down, it checks
+// if the stopped_ flag is already set.  If it is, the call is a no-op.
+
+void
+IOFetch::stop(Result result) {
+
+    if (!data_->stopped) {
+
+        // Mark the fetch as stopped to prevent other completion callbacks
+        // (invoked because of the calls to cancel()) from executing the
+        // cancel calls again.
+        //
+        // In a single threaded environment, the callbacks won't be invoked
+        // until this one completes. In a multi-threaded environment, they may
+        // well be, in which case the testing (and setting) of the stopped_
+        // variable should be done inside a mutex (and the stopped_ variable
+        // declared as "volatile").
+        //
+        // The numeric arguments indicate the debug level, with the lower
+        // numbers indicating the most important information.  The relative
+        // values are somewhat arbitrary.
+        //
+        // Although Logger::debug checks the debug flag internally, doing it
+        // below before calling Logger::debug avoids the overhead of a string
+        // conversion in the common case when debug is not enabled.
+        //
+        // TODO: Update testing of stopped_ if threads are used.
+        data_->stopped = true;
+        switch (result) {
+            case TIME_OUT:
+                if (logger.isDebugEnabled(1)) {
+                    logger.debug(20, ASIO_RECVTMO,
+                                 data_->remote_snd->getAddress().toText().c_str(),
+                                 static_cast<int>(data_->remote_snd->getPort()));
+                }
+                break;
+
+            case SUCCESS:
+                if (logger.isDebugEnabled(50)) {
+                    logger.debug(30, ASIO_FETCHCOMP,
+                                 data_->remote_rcv->getAddress().toText().c_str(),
+                                 static_cast<int>(data_->remote_rcv->getPort()));
+                }
+                break;
+
+            case STOPPED:
+                // Fetch has been stopped for some other reason.  This is
+                // allowed but as it is unusual it is logged, but with a lower
+                // debug level than a timeout (which is totally normal).
+                logger.debug(1, ASIO_FETCHSTOP,
+                             data_->remote_snd->getAddress().toText().c_str(),
+                             static_cast<int>(data_->remote_snd->getPort()));
+                break;
+
+            default:
+                logger.error(ASIO_UNKRESULT, static_cast<int>(result),
+                             data_->remote_snd->getAddress().toText().c_str(),
+                             static_cast<int>(data_->remote_snd->getPort()));
+        }
+
+        // Stop requested, cancel and I/O's on the socket and shut it down,
+        // and cancel the timer.
+        data_->socket->cancel();
+        data_->socket->close();
+
+        data_->timer.cancel();
+
+        // Execute the I/O completion callback (if present).
+        if (data_->callback) {
+            (*(data_->callback))(result);
+        }
+    }
+}
+
+// Log an error - called on I/O failure
+
+void IOFetch::logIOFailure(asio::error_code ec) {
+
+    // Should only get here with a known error code.
+    assert((data_->origin == ASIO_OPENSOCK) ||
+           (data_->origin == ASIO_SENDSOCK) ||
+           (data_->origin == ASIO_RECVSOCK) ||
+           (data_->origin == ASIO_UNKORIGIN));
+
+    static const char* PROTOCOL[2] = {"TCP", "UDP"};
+    logger.error(data_->origin,
+                 ec.value(),
+                 ((data_->remote_snd->getProtocol() == IPPROTO_TCP) ?
+                     PROTOCOL[0] : PROTOCOL[1]),
+                 data_->remote_snd->getAddress().toText().c_str(),
+                 static_cast<int>(data_->remote_snd->getPort()));
+}
+
+} // namespace asiodns
+} // namespace isc
+
diff --git a/src/lib/asiodns/io_fetch.h b/src/lib/asiodns/io_fetch.h
new file mode 100644
index 0000000..0a11fb7
--- /dev/null
+++ b/src/lib/asiodns/io_fetch.h
@@ -0,0 +1,182 @@
+// 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.
+
+#ifndef __IO_FETCH_H
+#define __IO_FETCH_H 1
+
+#include <config.h>
+
+#include <boost/shared_array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+#include <coroutine.h>
+
+#include <asio/error_code.hpp>
+#include <asiolink/io_service.h>
+#include <asiolink/io_address.h>
+
+#include <dns/buffer.h>
+#include <dns/question.h>
+
+namespace isc {
+namespace asiodns {
+
+// Forward declarations
+class IOFetchData;
+
+/// \brief Upstream Fetch Processing
+///
+/// IOFetch is the class used to send upstream fetches and to handle responses.
+///
+/// \param E Endpoint type to use.
+
+class IOFetch : public coroutine {
+public:
+    /// \brief Protocol to use on the fetch
+    enum Protocol {
+        UDP = 0,
+        TCP = 1
+    };
+
+    /// \brief Origin of Asynchronous I/O Call
+    ///
+    /// Indicates what initiated an asynchronous I/O call and used in deciding
+    /// what error message to output if the I/O fails.
+    enum Origin {
+        NONE = 0,           ///< No asynchronous call outstanding
+        OPEN = 1,
+        SEND = 2,
+        RECEIVE = 3,
+        CLOSE = 4
+    };
+
+    /// \brief Result of Upstream Fetch
+    ///
+    /// Note that this applies to the status of I/Os in the fetch - a fetch
+    /// that resulted in a packet being received from the server is a SUCCESS,
+    /// even if the contents of the packet indicate that some error occurred.
+    enum Result {
+        SUCCESS = 0,        ///< Success, fetch completed
+        TIME_OUT = 1,       ///< Failure, fetch timed out
+        STOPPED = 2,        ///< Control code, fetch has been stopped
+        NOTSET = 3          ///< For testing, indicates value not set
+    };
+
+    // The next enum is a "trick" to allow constants to be defined in a class
+    // declaration.
+
+    /// \brief Integer Constants
+    enum {
+        STAGING_LENGTH = 8192   ///< Size of staging buffer
+    };
+
+    /// \brief I/O Fetch Callback
+    ///
+    /// Class of callback object for when the fetch itself has completed - an
+    /// object of this class is passed to the IOFetch constructor and its
+    /// operator() method called when the fetch completes.
+    ///
+    /// Note the difference between the two operator() methods:
+    /// - IOFetch::operator() callback is called when an asynchronous I/O has
+    ///   completed.
+    /// - IOFetch::Callback::operator() is called when an upstream fetch - which
+    ///   may have involved several asynchronous I/O operations - has completed.
+    ///
+    /// This is an abstract class.
+    class Callback {
+    public:
+        /// \brief Default Constructor
+        Callback()
+        {}
+
+        /// \brief Virtual Destructor
+        virtual ~Callback()
+        {}
+
+        /// \brief Callback method
+        ///
+        /// This is the method called when the fetch completes.
+        ///
+        /// \param result Result of the fetch
+        virtual void operator()(Result result) = 0;
+    };
+
+    /// \brief Constructor.
+    ///
+    /// Creates the object that will handle the upstream fetch.
+    ///
+    /// TODO: Need to randomise the source port
+    ///
+    /// \param protocol Fetch protocol, either IOFetch::TCP or IOFetch::UDP
+    /// \param service I/O Service object to handle the asynchronous
+    ///     operations.
+    /// \param question DNS question to send to the upstream server.
+    /// \param buff Output buffer into which the response (in wire format)
+    ///     is written (if a response is received).
+    /// \param cb Callback object containing the callback to be called
+    ///     when we terminate.  The caller is responsible for managing this
+    ///     object and deleting it if necessary.
+    /// \param address IP address of upstream server
+    /// \param port Port to which to connect on the upstream server
+    /// (default = 53)
+    /// \param wait Timeout for the fetch (in ms).  The default value of
+    ///     -1 indicates no timeout.
+    IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+        const isc::dns::Question& question,
+        const isc::asiolink::IOAddress& address,
+        uint16_t port, isc::dns::OutputBufferPtr& buff, Callback* cb,
+        int wait = -1);
+
+    /// \brief Return Current Protocol
+    ///
+    /// \return Protocol associated with this IOFetch object.
+    Protocol getProtocol() const;
+
+    /// \brief Coroutine entry point
+    ///
+    /// The operator() method is the method in which the coroutine code enters
+    /// this object when an operation has been completed.
+    ///
+    /// \param ec Error code, the result of the last asynchronous I/O operation.
+    /// \param length Amount of data received on the last asynchronous read
+    void operator()(asio::error_code ec = asio::error_code(), size_t length = 0);
+
+    /// \brief Terminate query
+    ///
+    /// This method can be called at any point.  It terminates the current
+    /// query with the specified reason.
+    ///
+    /// \param reason Reason for terminating the query
+    void stop(Result reason = STOPPED);
+
+private:
+    /// \brief Log I/O Failure
+    ///
+    /// Records an I/O failure to the log file
+    ///
+    /// \param ec ASIO error code
+    void logIOFailure(asio::error_code ec);
+
+    // Member variables.  All data is in a structure pointed to by a shared
+    // pointer.  The IOFetch object is copied a number of times during its
+    // life, and only requiring a pointer to be copied reduces overhead.
+    boost::shared_ptr<IOFetchData>  data_;   ///< Private data
+
+};
+
+} // namespace asiodns
+} // namespace isc
+
+#endif // __IO_FETCH_H
diff --git a/src/lib/asiodns/tcp_server.cc b/src/lib/asiodns/tcp_server.cc
index db59551..7655df0 100644
--- a/src/lib/asiodns/tcp_server.cc
+++ b/src/lib/asiodns/tcp_server.cc
@@ -27,7 +27,7 @@
 #include <asiolink/dummy_io_cb.h>
 #include <asiolink/tcp_endpoint.h>
 #include <asiolink/tcp_socket.h>
-#include <asiolink/tcp_server.h>
+#include <tcp_server.h>
 
 
 using namespace asio;
@@ -36,8 +36,10 @@ using asio::ip::tcp;
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::asiolink;
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /// The following functions implement the \c TCPServer class.
 ///
@@ -235,5 +237,5 @@ TCPServer::resume(const bool done) {
     io_.post(*this);
 }
 
-} // namespace asiolink
-
+} // namespace asiodns
+} // namespace isc
diff --git a/src/lib/asiodns/tcp_server.h b/src/lib/asiodns/tcp_server.h
index 2fe0d37..3b00293 100644
--- a/src/lib/asiodns/tcp_server.h
+++ b/src/lib/asiodns/tcp_server.h
@@ -24,9 +24,12 @@
 
 #include <asiolink/asiolink.h>
 #include <coroutine.h>
+#include "dns_server.h"
+#include "dns_lookup.h"
+#include "dns_answer.h"
 
-
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /// \brief A TCP-specific \c DNSServer object.
 ///
@@ -36,7 +39,7 @@ class TCPServer : public virtual DNSServer, public virtual coroutine {
 public:
     explicit TCPServer(asio::io_service& io_service,
                        const asio::ip::address& addr, const uint16_t port, 
-                       const SimpleCallback* checkin = NULL,
+                       const isc::asiolink::SimpleCallback* checkin = NULL,
                        const DNSLookup* lookup = NULL,
                        const DNSAnswer* answer = NULL);
 
@@ -95,7 +98,7 @@ private:
 
     // \c IOMessage and \c Message objects to be passed to the
     // DNS lookup and answer providers
-    boost::shared_ptr<asiolink::IOMessage> io_message_;
+    boost::shared_ptr<isc::asiolink::IOMessage> io_message_;
     isc::dns::MessagePtr query_message_;
     isc::dns::MessagePtr answer_message_;
 
@@ -108,13 +111,14 @@ private:
     bool done_;
 
     // Callback functions provided by the caller
-    const SimpleCallback* checkin_callback_;
+    const isc::asiolink::SimpleCallback* checkin_callback_;
     const DNSLookup* lookup_callback_;
     const DNSAnswer* answer_callback_;
 
-    boost::shared_ptr<IOEndpoint> peer_;
-    boost::shared_ptr<IOSocket> iosock_;
+    boost::shared_ptr<isc::asiolink::IOEndpoint> peer_;
+    boost::shared_ptr<isc::asiolink::IOSocket> iosock_;
 };
 
-}      // namespace asiolink
+} // namespace asiodns
+} // namespace isc
 #endif // __TCP_SERVER_H
diff --git a/src/lib/asiodns/tests/Makefile.am b/src/lib/asiodns/tests/Makefile.am
index bb29074..2153755 100644
--- a/src/lib/asiodns/tests/Makefile.am
+++ b/src/lib/asiodns/tests/Makefile.am
@@ -16,8 +16,11 @@ TESTS =
 if HAVE_GTEST
 TESTS += run_unittests
 run_unittests_SOURCES  = run_unittests.cc
+run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.h
+run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc
 run_unittests_SOURCES += io_service_unittest.cc
 run_unittests_SOURCES += dns_server_unittest.cc
+run_unittests_SOURCES += io_fetch_unittest.cc
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 
@@ -27,6 +30,7 @@ run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
 run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
 run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
 run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
+run_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libasiodns.la
 
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) 
 
diff --git a/src/lib/asiodns/tests/dns_server_unittest.cc b/src/lib/asiodns/tests/dns_server_unittest.cc
index 5b8b683..0d5a554 100644
--- a/src/lib/asiodns/tests/dns_server_unittest.cc
+++ b/src/lib/asiodns/tests/dns_server_unittest.cc
@@ -18,10 +18,10 @@
 #include <asio.hpp>
 #include <asiolink/io_endpoint.h>
 #include <asiolink/io_error.h>
-#include <asiolink/udp_server.h>
-#include <asiolink/tcp_server.h>
-#include <asiolink/dns_answer.h>
-#include <asiolink/dns_lookup.h>
+#include <asiodns/udp_server.h>
+#include <asiodns/tcp_server.h>
+#include <asiodns/dns_answer.h>
+#include <asiodns/dns_lookup.h>
 #include <string>
 #include <csignal>
 #include <unistd.h> //for alarm
@@ -65,7 +65,8 @@
 /// involved so the message sending between client and server is plain text
 /// And the valid checker, question lookup and answer composition are dummy.
 
-using namespace asiolink;
+using namespace isc::asiolink;
+using namespace isc::asiodns;
 using namespace asio;
 namespace {
 static const std::string server_ip = "127.0.0.1";
diff --git a/src/lib/asiodns/tests/io_fetch_unittest.cc b/src/lib/asiodns/tests/io_fetch_unittest.cc
new file mode 100644
index 0000000..eba5809
--- /dev/null
+++ b/src/lib/asiodns/tests/io_fetch_unittest.cc
@@ -0,0 +1,726 @@
+// Copyright (C) 2011  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.
+
+#include <algorithm>
+#include <cstdlib>
+#include <string>
+#include <iostream>
+#include <iomanip>
+#include <iterator>
+#include <vector>
+
+#include <gtest/gtest.h>
+#include <boost/bind.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+#include <asio.hpp>
+
+#include <dns/buffer.h>
+#include <dns/question.h>
+#include <dns/message.h>
+#include <dns/messagerenderer.h>
+#include <dns/opcode.h>
+#include <dns/name.h>
+#include <dns/rcode.h>
+
+#include <asiolink/asiolink_utilities.h>
+#include <asiolink/io_address.h>
+#include <asiolink/io_endpoint.h>
+#include <asiolink/io_service.h>
+#include <asiodns/io_fetch.h>
+
+using namespace asio;
+using namespace isc::dns;
+using namespace asio::ip;
+using namespace std;
+using namespace isc::asiolink;
+
+namespace isc {
+namespace asiodns {
+
+const asio::ip::address TEST_HOST(asio::ip::address::from_string("127.0.0.1"));
+const uint16_t TEST_PORT(5301);
+const int SEND_INTERVAL = 250;      // Interval in ms between TCP sends
+const size_t MAX_SIZE = 64 * 1024;  // Should be able to take 64kB
+
+// The tests are complex, so debug output has been left in (although disabled).
+// Set this to true to enable it.
+const bool DEBUG = false;
+
+/// \brief Test fixture for the asiolink::IOFetch.
+class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Callback
+{
+public:
+    IOService       service_;       ///< Service to run the query
+    IOFetch::Result expected_;      ///< Expected result of the callback
+    bool            run_;           ///< Did the callback run already?
+    Question        question_;      ///< What to ask
+    OutputBufferPtr result_buff_;   ///< Buffer to hold result of fetch
+    OutputBufferPtr msgbuf_;        ///< Buffer corresponding to known question
+    IOFetch         udp_fetch_;     ///< For UDP query test
+    IOFetch         tcp_fetch_;     ///< For TCP query test
+    IOFetch::Protocol protocol_;    ///< Protocol being tested
+    size_t          cumulative_;    ///< Cumulative data received by "server".
+    deadline_timer  timer_;         ///< Timer to measure timeouts
+
+    // The next member is the buffer in which the "server" (implemented by the
+    // response handler methods in this class) receives the question sent by the
+    // fetch object.
+    uint8_t         receive_buffer_[MAX_SIZE]; ///< Server receive buffer
+    OutputBufferPtr expected_buffer_;          ///< Data we expect to receive
+    vector<uint8_t> send_buffer_;           ///< Server send buffer
+    uint16_t        send_cumulative_;       ///< Data sent so far
+
+    // Other data.
+    string          return_data_;           ///< Data returned by server
+    string          test_data_;             ///< Large string - here for convenience
+    bool            debug_;                 ///< true to enable debug output
+    size_t          tcp_send_size_;         ///< Max size of TCP send
+    uint8_t         qid_0;                  ///< First octet of qid
+    uint8_t         qid_1;                  ///< Second octet of qid
+
+    bool            tcp_short_send_;        ///< If set to true, we do not send
+                                            ///  all data in the tcp response
+
+    /// \brief Constructor
+    IOFetchTest() :
+        service_(),
+        expected_(IOFetch::NOTSET),
+        run_(false),
+        question_(Name("example.net"), RRClass::IN(), RRType::A()),
+        result_buff_(new OutputBuffer(512)),
+        msgbuf_(new OutputBuffer(512)),
+        udp_fetch_(IOFetch::UDP, service_, question_, IOAddress(TEST_HOST),
+            TEST_PORT, result_buff_, this, 100),
+        tcp_fetch_(IOFetch::TCP, service_, question_, IOAddress(TEST_HOST),
+            TEST_PORT, result_buff_, this, (16 * SEND_INTERVAL)),
+                                        // Timeout interval chosen to ensure no timeout
+        protocol_(IOFetch::TCP),        // for initialization - will be changed
+        cumulative_(0),
+        timer_(service_.get_io_service()),
+        receive_buffer_(),
+        expected_buffer_(new OutputBuffer(512)),
+        send_buffer_(),
+        send_cumulative_(0),
+        return_data_(""),
+        test_data_(""),
+        debug_(DEBUG),
+        tcp_send_size_(0),
+        qid_0(0),
+        qid_1(0),
+        tcp_short_send_(false)
+    {
+        // Construct the data buffer for question we expect to receive.
+        Message msg(Message::RENDER);
+        msg.setQid(0);
+        msg.setOpcode(Opcode::QUERY());
+        msg.setRcode(Rcode::NOERROR());
+        msg.setHeaderFlag(Message::HEADERFLAG_RD);
+        msg.addQuestion(question_);
+        MessageRenderer renderer(*msgbuf_);
+        msg.toWire(renderer);
+        MessageRenderer renderer2(*expected_buffer_);
+        msg.toWire(renderer2);
+
+        // Initialize the test data to be returned: tests will return a
+        // substring of this data. (It's convenient to have this as a member of
+        // the class.)
+        //
+        // We could initialize the data with a single character, but as an added
+        // check we'll make ssre that it has some structure.
+
+        test_data_.clear();
+        test_data_.reserve(MAX_SIZE);
+        while (test_data_.size() < MAX_SIZE) {
+            test_data_ += "A message to be returned to the client that has "
+                          "some sort of structure.";
+        }
+    }
+
+    /// \brief UDP Response handler (the "remote UDP DNS server")
+    ///
+    /// When IOFetch is sending data, this response handler emulates the remote
+    /// DNS server.  It checks that the data sent by the IOFetch object is what
+    /// was expected to have been sent, then sends back a known buffer of data.
+    ///
+    /// \param remote Endpoint to which to send the answer
+    /// \param socket Socket to use to send the answer
+    /// \param ec ASIO error code, completion code of asynchronous I/O issued
+    ///        by the "server" to receive data.
+    /// \param bad_qid If set to true, the QID in the response will be mangled
+    /// \param second_send If set to true, (and bad_qid is too), after the
+    ///        mangled qid response has been sent, a second packet will be
+    ///        sent with the correct QID.
+    /// \param length Amount of data received.
+    void udpReceiveHandler(udp::endpoint* remote, udp::socket* socket,
+                    error_code ec = error_code(), size_t length = 0,
+                    bool bad_qid = false, bool second_send = false) {
+        if (debug_) {
+            cout << "udpReceiveHandler(): error = " << ec.value() <<
+                    ", length = " << length << endl;
+        }
+
+        // The QID in the incoming data is random so set it to 0 for the
+        // data comparison check. (It is set to 0 in the buffer containing
+        // the expected data.)
+        qid_0 = receive_buffer_[0];
+        qid_1 = receive_buffer_[1];
+        receive_buffer_[0] = receive_buffer_[1] = 0;
+
+        // Check that length of the received data and the expected data are
+        // identical, then check that the data is identical as well.
+        EXPECT_EQ(msgbuf_->getLength(), length);
+        EXPECT_TRUE(equal(receive_buffer_, (receive_buffer_ + length - 1),
+        static_cast<const uint8_t*>(msgbuf_->getData())));
+
+        // Return a message back to the IOFetch object.
+        if (!bad_qid) {
+            expected_buffer_->writeUint8At(qid_0, 0);
+            expected_buffer_->writeUint8At(qid_1, 1);
+        } else {
+            expected_buffer_->writeUint8At(qid_0 + 1, 0);
+            expected_buffer_->writeUint8At(qid_1 + 1, 1);
+        }
+        socket->send_to(asio::buffer(expected_buffer_->getData(), length), *remote);
+
+        if (bad_qid && second_send) {
+            expected_buffer_->writeUint8At(qid_0, 0);
+            expected_buffer_->writeUint8At(qid_1, 1);
+            socket->send_to(asio::buffer(expected_buffer_->getData(),
+                            expected_buffer_->getLength()), *remote);
+        }
+        if (debug_) {
+            cout << "udpReceiveHandler(): returned " << expected_buffer_->getLength() <<
+                    " bytes to the client" << endl;
+        }
+    }
+
+    /// \brief Completion Handler for accepting TCP data
+    ///
+    /// Called when the remote system connects to the "server".  It issues
+    /// an asynchronous read on the socket to read data.
+    ///
+    /// \param socket Socket on which data will be received
+    /// \param ec Boost error code, value should be zero.
+    void tcpAcceptHandler(tcp::socket* socket, error_code ec = error_code())
+    {
+        if (debug_) {
+            cout << "tcpAcceptHandler(): error = " << ec.value() << endl;
+        }
+
+        // Expect that the accept completed without a problem.
+        EXPECT_EQ(0, ec.value());
+
+        // Work out the maximum size of data we can send over it when we
+        // respond, then subtract 1kB or so for safety.
+        tcp::socket::send_buffer_size send_size;
+        socket->get_option(send_size);
+        if (send_size.value() < (2 * 1024)) {
+            FAIL() << "TCP send size is less than 2kB";
+        } else {
+            tcp_send_size_ = send_size.value() - 1024;
+            if (debug_) {
+                cout << "tcpacceptHandler(): will use send size = " << tcp_send_size_ << endl;
+            }
+        }
+
+        // Initiate a read on the socket.
+        cumulative_ = 0;
+        socket->async_receive(asio::buffer(receive_buffer_, sizeof(receive_buffer_)),
+            boost::bind(&IOFetchTest::tcpReceiveHandler, this, socket, _1, _2));
+    }
+
+    /// \brief Completion handler for receiving TCP data
+    ///
+    /// When IOFetch is sending data, this response handler emulates the remote
+    /// DNS server.  It that all the data sent by the IOFetch object has been
+    /// received, issuing another read if not.  If the data is complete, it is
+    /// compared to what is expected and a reply sent back to the IOFetch.
+    ///
+    /// \param socket Socket to use to send the answer
+    /// \param ec ASIO error code, completion code of asynchronous I/O issued
+    ///        by the "server" to receive data.
+    /// \param length Amount of data received.
+    void tcpReceiveHandler(tcp::socket* socket, error_code ec = error_code(),
+                           size_t length = 0)
+    {
+        if (debug_) {
+            cout << "tcpReceiveHandler(): error = " << ec.value() <<
+                    ", length = " << length << endl;
+        }
+        // Expect that the receive completed without a problem.
+        EXPECT_EQ(0, ec.value());
+
+        // If we haven't received all the data, issue another read.
+        cumulative_ += length;
+        bool complete = false;
+        if (cumulative_ > 2) {
+            uint16_t dns_length = readUint16(receive_buffer_);
+            complete = ((dns_length + 2) == cumulative_);
+        }
+
+        if (!complete) {
+            socket->async_receive(asio::buffer((receive_buffer_ + cumulative_),
+                (sizeof(receive_buffer_) - cumulative_)),
+                boost::bind(&IOFetchTest::tcpReceiveHandler, this, socket, _1, _2));
+            return;
+        }
+
+        // Check that length of the DNS message received is that expected, then
+        // compare buffers, zeroing the QID in the received buffer to match
+        // that set in our expected question.  Note that due to the length
+        // field the QID in the received buffer is in the third and fourth
+        // bytes.
+        EXPECT_EQ(msgbuf_->getLength() + 2, cumulative_);
+        qid_0 = receive_buffer_[2];
+        qid_1 = receive_buffer_[3];
+
+        receive_buffer_[2] = receive_buffer_[3] = 0;
+        EXPECT_TRUE(equal((receive_buffer_ + 2), (receive_buffer_ + cumulative_ - 2),
+            static_cast<const uint8_t*>(msgbuf_->getData())));
+
+        // ... and return a message back.  This has to be preceded by a two-byte
+        // count field.
+
+        send_buffer_.clear();
+        send_buffer_.push_back(0);
+        send_buffer_.push_back(0);
+        writeUint16(return_data_.size(), &send_buffer_[0]);
+        copy(return_data_.begin(), return_data_.end(), back_inserter(send_buffer_));
+        if (return_data_.size() >= 2) {
+            send_buffer_[2] = qid_0;
+            send_buffer_[3] = qid_1;
+        }
+        // Send the data.  This is done in multiple writes with a delay between
+        // each to check that the reassembly of TCP packets from fragments works.
+        send_cumulative_ = 0;
+        tcpSendData(socket);
+    }
+
+    /// \brief Sent Data Over TCP
+    ///
+    /// Send the TCP data back to the IOFetch object.  The data is sent in
+    /// three chunks - two of 16 bytes and the remainder, with a 250ms gap
+    /// between each. (Amounts of data smaller than one 32 bytes are sent in
+    /// one or two packets.)
+    ///
+    /// \param socket Socket over which send should take place
+    void tcpSendData(tcp::socket* socket) {
+        if (debug_) {
+            cout << "tcpSendData()" << endl;
+        }
+
+        // Decide what to send based on the cumulative count.  At most we'll do
+        // two chunks of 16 bytes (with a 250ms gap between) and then the
+        // remainder.
+        uint8_t* send_ptr = &send_buffer_[send_cumulative_];
+                                    // Pointer to data to send
+        size_t amount = 16;         // Amount of data to send
+        if (send_cumulative_ < (2 * amount)) {
+            
+            // First or second time through, send at most 16 bytes
+            amount = min(amount, (send_buffer_.size() - send_cumulative_));
+
+        } else {
+
+            // For all subsequent times, send the remainder, maximised to
+            // whatever we have chosen for the maximum send size.
+            amount = min(tcp_send_size_,
+                        (send_buffer_.size() - send_cumulative_));
+        }
+
+        // This is for the short send test; reduce the actual amount of
+        // data we send
+        if (tcp_short_send_) {
+            if (debug_) {
+                cout << "tcpSendData(): sending incomplete data (" <<
+                        (amount - 1) << " of " << amount << " bytes)" <<
+                        endl;
+            }
+            --amount;
+        } else {
+            if (debug_) {
+                cout << "tcpSendData(): sending " << amount << " bytes" << endl;
+            }
+        }
+
+        // ... and send it.  The amount sent is also passed as the first
+        // argument of the send callback, as a check.
+        socket->async_send(asio::buffer(send_ptr, amount),
+                           boost::bind(&IOFetchTest::tcpSendHandler, this,
+                                       amount, socket, _1, _2));
+    }
+
+    /// \brief Completion Handler for Sending TCP data
+    ///
+    /// Called when the asynchronous send of data back to the IOFetch object
+    /// by the TCP "server" in this class has completed.  (This send has to
+    /// be asynchronous because control needs to return to the caller in order
+    /// for the IOService "run()" method to be called to run the handlers.)
+    ///
+    /// If not all the data has been sent, a short delay is instigated (during
+    /// which control returns to the IOService).  This should force the queued
+    /// data to actually be sent and the IOFetch receive handler to be triggered.
+    /// In this way, the ability of IOFetch to handle fragmented TCP packets
+    /// should be checked.
+    ///
+    /// \param expected Number of bytes that were expected to have been sent.
+    /// \param socket Socket over which the send took place.  Only used to
+    ///        pass back to the send method.
+    /// \param ec Boost error code, value should be zero.
+    /// \param length Number of bytes sent.
+    void tcpSendHandler(size_t expected, tcp::socket* socket,
+                        error_code ec = error_code(), size_t length = 0)
+    {
+        if (debug_) {
+            cout << "tcpSendHandler(): error = " << ec.value() <<
+                    ", length = " << length << endl;
+        }
+
+        EXPECT_EQ(0, ec.value());       // Expect no error
+        EXPECT_EQ(expected, length);    // And that amount sent is as expected
+
+        // Do we need to send more?
+        send_cumulative_ += length;
+        if (send_cumulative_ < send_buffer_.size()) {
+
+            // Yes - set up a timer:  the callback handler for the timer is
+            // tcpSendData, which will then send the next chunk.  We pass the
+            // socket over which data should be sent as an argument to that
+            // function.
+            timer_.expires_from_now(boost::posix_time::milliseconds(SEND_INTERVAL));
+            timer_.async_wait(boost::bind(&IOFetchTest::tcpSendData, this,
+                                          socket));
+        }
+    }
+
+    /// \brief Fetch completion callback
+    ///
+    /// This is the callback's operator() method which is called when the fetch
+    /// is complete.  It checks that the data received is the wire format of the
+    /// data sent back by the server.
+    ///
+    /// \param result Result indicated by the callback
+    void operator()(IOFetch::Result result) {
+        if (debug_) {
+            cout << "operator()(): result = " << result << endl;
+        }
+
+        EXPECT_EQ(expected_, result);   // Check correct result returned
+        EXPECT_FALSE(run_);             // Check it is run only once
+        run_ = true;                    // Note success
+
+        // If the expected result for SUCCESS, then this should have been called
+        // when one of the "servers" in this class has sent back return_data_.
+        // Check the data is as expected/
+        if (expected_ == IOFetch::SUCCESS) {
+            // In the case of UDP, we actually send back a real looking packet
+            // in the case of TCP, we send back a 'random' string
+            if (protocol_ == IOFetch::UDP) {
+                EXPECT_EQ(expected_buffer_->getLength(), result_buff_->getLength());
+                EXPECT_EQ(0, memcmp(expected_buffer_->getData(), result_buff_->getData(),
+                          expected_buffer_->getLength()));
+            } else {
+                EXPECT_EQ(return_data_.size(), result_buff_->getLength());
+                // Overwrite the random qid with our own data for the
+                // comparison to succeed
+                if (result_buff_->getLength() >= 2) {
+                    result_buff_->writeUint8At(return_data_[0], 0);
+                    result_buff_->writeUint8At(return_data_[1], 1);
+                }
+                const uint8_t* start = static_cast<const uint8_t*>(result_buff_->getData());
+                EXPECT_TRUE(equal(return_data_.begin(), return_data_.end(), start));
+            }
+        }
+
+        // ... and cause the run loop to exit.
+        service_.stop();
+    }
+
+    // The next set of methods are the tests themselves.  A number of the TCP
+    // and UDP tests are very similar.
+
+    /// \brief Check for stop()
+    ///
+    /// Test that when we run the query and stop it after it was run, it returns
+    /// "stopped" correctly. (That is why stop() is posted to the service_ as
+    /// well instead of calling it.)
+    ///
+    /// \param protocol Test protocol
+    /// \param fetch Fetch object being tested
+    void stopTest(IOFetch::Protocol protocol, IOFetch& fetch) {
+        protocol_ = protocol;
+        expected_ = IOFetch::STOPPED;
+
+        // Post the query
+        service_.get_io_service().post(fetch);
+
+        // Post query_.stop() (yes, the boost::bind thing is just
+        // query_.stop()).
+        service_.get_io_service().post(
+            boost::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
+
+        // Run both of them.  run() returns when everything in the I/O service
+        // queue has completed.
+        service_.run();
+        EXPECT_TRUE(run_);
+    }
+
+    /// \brief Premature stop test
+    ///
+    /// Test that when we queue the query to service_ and call stop() before it
+    /// gets executed, it acts sanely as well (eg. has the same result as
+    /// running stop() after - calls the callback).
+    ///
+    /// \param protocol Test protocol
+    /// \param fetch Fetch object being tested
+    void prematureStopTest(IOFetch::Protocol protocol, IOFetch& fetch) {
+        protocol_ = protocol;
+        expected_ = IOFetch::STOPPED;
+
+        // Stop before it is started
+        fetch.stop();
+        service_.get_io_service().post(fetch);
+
+        service_.run();
+        EXPECT_TRUE(run_);
+    }
+
+    /// \brief Timeout test
+    ///
+    /// Test that fetch times out when no answer arrives.
+    ///
+    /// \param protocol Test protocol
+    /// \param fetch Fetch object being tested
+    void timeoutTest(IOFetch::Protocol protocol, IOFetch& fetch) {
+        protocol_ = protocol;
+        expected_ = IOFetch::TIME_OUT;
+
+        service_.get_io_service().post(fetch);
+        service_.run();
+        EXPECT_TRUE(run_);
+    }
+
+    /// \brief Send/Receive Test
+    ///
+    /// Send a query to the server then receives a response.
+    ///
+    /// \param Test data to return to client
+    /// \param short_send If true, do not send all data
+    ///                   (should result in timeout)
+    void tcpSendReturnTest(const std::string& return_data, bool short_send = false) {
+        if (debug_) {
+            cout << "tcpSendReturnTest(): data size = " << return_data.size() << endl;
+        }
+        return_data_ = return_data;
+        protocol_ = IOFetch::TCP;
+        if (short_send) {
+            tcp_short_send_ = true;
+            expected_ = IOFetch::TIME_OUT;
+        } else {
+            expected_ = IOFetch::SUCCESS;
+        }
+
+        // Socket into which the connection will be accepted.
+        tcp::socket socket(service_.get_io_service());
+
+        // Acceptor object - called when the connection is made, the handler
+        // will initiate a read on the socket.
+        tcp::acceptor acceptor(service_.get_io_service(),
+                               tcp::endpoint(tcp::v4(), TEST_PORT));
+        acceptor.async_accept(socket,
+            boost::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, _1));
+
+        // Post the TCP fetch object to send the query and receive the response.
+        service_.get_io_service().post(tcp_fetch_);
+
+        // ... and execute all the callbacks.  This exits when the fetch
+        // completes.
+        service_.run();
+        EXPECT_TRUE(run_);  // Make sure the callback did execute
+
+        // Tidy up
+        socket.close();
+    }
+
+    /// Perform a send/receive test over UDP
+    ///
+    /// \param bad_qid If true, do the test where the QID is mangled
+    ///                in the response
+    /// \param second_send If true, do the test where the QID is
+    ///                    mangled in the response, but a second
+    ///                    (correct) packet is used
+    void udpSendReturnTest(bool bad_qid, bool second_send) {
+        protocol_ = IOFetch::UDP;
+
+        // Set up the server.
+        udp::socket socket(service_.get_io_service(), udp::v4());
+        socket.set_option(socket_base::reuse_address(true));
+        socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
+        return_data_ = "Message returned to the client";
+
+        udp::endpoint remote;
+        socket.async_receive_from(asio::buffer(receive_buffer_, sizeof(receive_buffer_)),
+            remote,
+            boost::bind(&IOFetchTest::udpReceiveHandler, this, &remote, &socket,
+                        _1, _2, bad_qid, second_send));
+        service_.get_io_service().post(udp_fetch_);
+        if (debug_) {
+            cout << "udpSendReceive: async_receive_from posted, waiting for callback" <<
+                    endl;
+        }
+        service_.run();
+
+        socket.close();
+
+        EXPECT_TRUE(run_);;
+    }
+};
+
+// Check the protocol
+TEST_F(IOFetchTest, Protocol) {
+    EXPECT_EQ(IOFetch::UDP, udp_fetch_.getProtocol());
+    EXPECT_EQ(IOFetch::TCP, tcp_fetch_.getProtocol());
+}
+
+// UDP Stop test - see IOFetchTest::stopTest() header.
+TEST_F(IOFetchTest, UdpStop) {
+    stopTest(IOFetch::UDP, udp_fetch_);
+}
+
+// UDP premature stop test - see IOFetchTest::prematureStopTest() header.
+TEST_F(IOFetchTest, UdpPrematureStop) {
+    prematureStopTest(IOFetch::UDP, udp_fetch_);
+}
+
+// UDP premature stop test - see IOFetchTest::timeoutTest() header.
+TEST_F(IOFetchTest, UdpTimeout) {
+    timeoutTest(IOFetch::UDP, udp_fetch_);
+}
+
+// UDP SendReceive test.  Set up a UDP server then ports a UDP fetch object.
+// This will send question_ to the server and receive the answer back from it.
+TEST_F(IOFetchTest, UdpSendReceive) {
+    expected_ = IOFetch::SUCCESS;
+
+    udpSendReturnTest(false, false);
+
+    EXPECT_TRUE(run_);;
+}
+
+TEST_F(IOFetchTest, UdpSendReceiveBadQid) {
+    expected_ = IOFetch::TIME_OUT;
+
+    udpSendReturnTest(true, false);
+
+    EXPECT_TRUE(run_);;
+}
+
+TEST_F(IOFetchTest, UdpSendReceiveBadQidResend) {
+    expected_ = IOFetch::SUCCESS;
+
+    udpSendReturnTest(true, true);
+
+    EXPECT_TRUE(run_);;
+}
+
+// Do the same tests for TCP transport
+
+TEST_F(IOFetchTest, TcpStop) {
+    stopTest(IOFetch::TCP, tcp_fetch_);
+}
+
+TEST_F(IOFetchTest, TcpPrematureStop) {
+    prematureStopTest(IOFetch::TCP, tcp_fetch_);
+}
+
+TEST_F(IOFetchTest, TcpTimeout) {
+    timeoutTest(IOFetch::TCP, tcp_fetch_);
+}
+
+// Test with values at or near 2, then at or near the chunk size (16 and 32
+// bytes, the sizes of the first two packets) then up to 65535.  These are done
+// in separate tests because in practice a new IOFetch is created for each
+// query/response exchange and we don't want to confuse matters in the test
+// by running the test with an IOFetch that has already done one exchange.
+//
+// Don't do 0 or 1; the server would not accept the packet
+// (since the length is too short to check the qid)
+TEST_F(IOFetchTest, TcpSendReceive2) {
+    tcpSendReturnTest(test_data_.substr(0, 2));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive3) {
+    tcpSendReturnTest(test_data_.substr(0, 3));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive15) {
+    tcpSendReturnTest(test_data_.substr(0, 15));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive16) {
+    tcpSendReturnTest(test_data_.substr(0, 16));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive17) {
+    tcpSendReturnTest(test_data_.substr(0, 17));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive31) {
+    tcpSendReturnTest(test_data_.substr(0, 31));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive32) {
+    tcpSendReturnTest(test_data_.substr(0, 32));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive33) {
+    tcpSendReturnTest(test_data_.substr(0, 33));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive4096) {
+    tcpSendReturnTest(test_data_.substr(0, 4096));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive8192) {
+    tcpSendReturnTest(test_data_.substr(0, 8192));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive16384) {
+    tcpSendReturnTest(test_data_.substr(0, 16384));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive32768) {
+    tcpSendReturnTest(test_data_.substr(0, 32768));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive65535) {
+    tcpSendReturnTest(test_data_.substr(0, 65535));
+}
+
+TEST_F(IOFetchTest, TcpSendReceive2ShortSend) {
+    tcpSendReturnTest(test_data_.substr(0, 2), true);
+}
+
+TEST_F(IOFetchTest, TcpSendReceive15ShortSend) {
+    tcpSendReturnTest(test_data_.substr(0, 15), true);
+}
+
+TEST_F(IOFetchTest, TcpSendReceive8192ShortSend) {
+    tcpSendReturnTest(test_data_.substr(0, 8192), true);
+}
+
+
+} // namespace asiodns
+} // namespace isc
diff --git a/src/lib/asiodns/tests/io_service_unittest.cc b/src/lib/asiodns/tests/io_service_unittest.cc
index 779d03e..cc64022 100644
--- a/src/lib/asiodns/tests/io_service_unittest.cc
+++ b/src/lib/asiodns/tests/io_service_unittest.cc
@@ -17,8 +17,10 @@
 
 #include <asio.hpp>
 #include <asiolink/asiolink.h>
+#include <asiodns/asiodns.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
+using namespace isc::asiodns;
 
 const char* const TEST_SERVER_PORT = "53535";
 const char* const TEST_CLIENT_PORT = "53536";
diff --git a/src/lib/asiodns/udp_server.cc b/src/lib/asiodns/udp_server.cc
index 5b48f28..4d2a0ed 100644
--- a/src/lib/asiodns/udp_server.cc
+++ b/src/lib/asiodns/udp_server.cc
@@ -27,8 +27,8 @@
 #include <asio/error.hpp>
 #include <asiolink/dummy_io_cb.h>
 #include <asiolink/udp_endpoint.h>
-#include <asiolink/udp_server.h>
 #include <asiolink/udp_socket.h>
+#include "udp_server.h"
 
 #include <dns/opcode.h>
 
@@ -38,8 +38,10 @@ using isc::log::dlog;
 
 using namespace std;
 using namespace isc::dns;
+using namespace isc::asiolink;
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 /*
  * Some of the member variables here are shared_ptrs and some are
@@ -318,4 +320,5 @@ UDPServer::hasAnswer() {
     return (data_->done_);
 }
 
-} // namespace asiolink
+} // namespace asiodns
+} // namespace isc
diff --git a/src/lib/asiodns/udp_server.h b/src/lib/asiodns/udp_server.h
index 1d37471..4c19544 100644
--- a/src/lib/asiodns/udp_server.h
+++ b/src/lib/asiodns/udp_server.h
@@ -19,14 +19,15 @@
 #error "asio.hpp must be included before including this, see asiolink.h as to why"
 #endif
 
-#include <asiolink/dns_server.h>
 #include <asiolink/simple_callback.h>
-#include <asiolink/dns_lookup.h>
-#include <asiolink/dns_answer.h>
+#include <asiodns/dns_answer.h>
+#include <asiodns/dns_lookup.h>
+#include <asiodns/dns_server.h>
 
 #include <coroutine.h>
 
-namespace asiolink {
+namespace isc {
+namespace asiodns {
 
 //
 // Asynchronous UDP server coroutine
@@ -47,7 +48,7 @@ public:
     /// \param answer the callbackprovider for DNS answer events
     explicit UDPServer(asio::io_service& io_service,
                        const asio::ip::address& addr, const uint16_t port,
-                       SimpleCallback* checkin = NULL,
+                       isc::asiolink::SimpleCallback* checkin = NULL,
                        DNSLookup* lookup = NULL,
                        DNSAnswer* answer = NULL);
 
@@ -102,5 +103,6 @@ private:
     boost::shared_ptr<Data> data_;
 };
 
-}      // namespace asiolink
+} // namespace asiodns
+} // namespace isc
 #endif // __UDP_SERVER_H
diff --git a/src/lib/asiolink/Makefile.am b/src/lib/asiolink/Makefile.am
index 745b0df..f1afe69 100644
--- a/src/lib/asiolink/Makefile.am
+++ b/src/lib/asiolink/Makefile.am
@@ -21,7 +21,6 @@ libasiolink_la_SOURCES += io_address.cc io_address.h
 libasiolink_la_SOURCES += io_asio_socket.h
 libasiolink_la_SOURCES += io_endpoint.cc io_endpoint.h
 libasiolink_la_SOURCES += io_error.h
-libasiolink_la_SOURCES += io_fetch.cc io_fetch.h
 libasiolink_la_SOURCES += io_message.h
 libasiolink_la_SOURCES += qid_gen.cc qid_gen.h
 libasiolink_la_SOURCES += io_service.h io_service.cc
diff --git a/src/lib/asiolink/asiodef.cc b/src/lib/asiolink/asiodef.cc
index 94c71b5..8e105c2 100644
--- a/src/lib/asiolink/asiodef.cc
+++ b/src/lib/asiolink/asiodef.cc
@@ -4,6 +4,7 @@
 #include <log/message_types.h>
 #include <log/message_initializer.h>
 
+namespace isc {
 namespace asiolink {
 
 extern const isc::log::MessageID ASIO_FETCHCOMP = "FETCHCOMP";
@@ -16,6 +17,7 @@ extern const isc::log::MessageID ASIO_UNKORIGIN = "UNKORIGIN";
 extern const isc::log::MessageID ASIO_UNKRESULT = "UNKRESULT";
 
 } // namespace asiolink
+} // namespace isc
 
 namespace {
 
diff --git a/src/lib/asiolink/asiodef.h b/src/lib/asiolink/asiodef.h
index ba77817..fdac741 100644
--- a/src/lib/asiolink/asiodef.h
+++ b/src/lib/asiolink/asiodef.h
@@ -5,6 +5,7 @@
 
 #include <log/message_types.h>
 
+namespace isc {
 namespace asiolink {
 
 extern const isc::log::MessageID ASIO_FETCHCOMP;
@@ -17,5 +18,6 @@ extern const isc::log::MessageID ASIO_UNKORIGIN;
 extern const isc::log::MessageID ASIO_UNKRESULT;
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __ASIODEF_H
diff --git a/src/lib/asiolink/asiolink_utilities.h b/src/lib/asiolink/asiolink_utilities.h
index 659e6a0..6ac423e 100644
--- a/src/lib/asiolink/asiolink_utilities.h
+++ b/src/lib/asiolink/asiolink_utilities.h
@@ -17,6 +17,7 @@
 
 #include <cstddef>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief Read Unsigned 16-Bit Integer from Buffer
@@ -57,5 +58,6 @@ writeUint16(uint16_t value, void* buffer) {
 }
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __ASIOLINK_UTILITIES_H
diff --git a/src/lib/asiolink/dummy_io_cb.h b/src/lib/asiolink/dummy_io_cb.h
index 0006b95..2081906 100644
--- a/src/lib/asiolink/dummy_io_cb.h
+++ b/src/lib/asiolink/dummy_io_cb.h
@@ -20,6 +20,7 @@
 #include <asio/error.hpp>
 #include <asio/error_code.hpp>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief Asynchronous I/O Completion Callback
@@ -55,5 +56,6 @@ public:
 };
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __DUMMY_IO_CB_H
diff --git a/src/lib/asiolink/interval_timer.cc b/src/lib/asiolink/interval_timer.cc
index 8efb102..0ed06eb 100644
--- a/src/lib/asiolink/interval_timer.cc
+++ b/src/lib/asiolink/interval_timer.cc
@@ -26,6 +26,7 @@
 #include <asiolink/interval_timer.h>
 #include <asiolink/io_service.h>
 
+namespace isc {
 namespace asiolink {
 
 class IntervalTimerImpl {
@@ -133,4 +134,5 @@ IntervalTimer::getInterval() const {
     return (impl_->getInterval());
 }
 
-}
+} // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/interval_timer.h b/src/lib/asiolink/interval_timer.h
index 6c43327..0831d44 100644
--- a/src/lib/asiolink/interval_timer.h
+++ b/src/lib/asiolink/interval_timer.h
@@ -19,6 +19,7 @@
 
 #include <asiolink/io_service.h>
 
+namespace isc {
 namespace asiolink {
 
 struct IntervalTimerImpl;
@@ -129,5 +130,6 @@ private:
     IntervalTimerImpl* impl_;
 };
 
-}      // namespace asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __ASIOLINK_INTERVAL_TIMER_H
diff --git a/src/lib/asiolink/io_address.cc b/src/lib/asiolink/io_address.cc
index 70e8374..7f7a6fc 100644
--- a/src/lib/asiolink/io_address.cc
+++ b/src/lib/asiolink/io_address.cc
@@ -31,6 +31,7 @@ using asio::ip::tcp;
 
 using namespace std;
 
+namespace isc {
 namespace asiolink {
 
 // XXX: we cannot simply construct the address in the initialization list,
@@ -62,4 +63,5 @@ IOAddress::getFamily() const {
     }
 }
 
-}
+} // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/io_address.h b/src/lib/asiolink/io_address.h
index 53c1a7a..655b727 100644
--- a/src/lib/asiolink/io_address.h
+++ b/src/lib/asiolink/io_address.h
@@ -26,6 +26,7 @@
 
 #include <exceptions/exceptions.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c IOAddress class represents an IP addresses (version
@@ -119,5 +120,6 @@ private:
     asio::ip::address asio_address_;
 };
 
-}      // asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __IO_ADDRESS_H
diff --git a/src/lib/asiolink/io_asio_socket.h b/src/lib/asiolink/io_asio_socket.h
index ac793a6..d618ff8 100644
--- a/src/lib/asiolink/io_asio_socket.h
+++ b/src/lib/asiolink/io_asio_socket.h
@@ -31,7 +31,7 @@
 #include <asiolink/io_error.h>
 #include <asiolink/io_socket.h>
 
-
+namespace isc {
 namespace asiolink {
 
 /// \brief Socket not open
@@ -395,5 +395,6 @@ private:
 };
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __IO_ASIO_SOCKET_H
diff --git a/src/lib/asiolink/io_endpoint.cc b/src/lib/asiolink/io_endpoint.cc
index e0b1a9e..63830a5 100644
--- a/src/lib/asiolink/io_endpoint.cc
+++ b/src/lib/asiolink/io_endpoint.cc
@@ -28,6 +28,7 @@
 
 using namespace std;
 
+namespace isc {
 namespace asiolink {
 
 const IOEndpoint*
@@ -57,4 +58,5 @@ IOEndpoint::operator!=(const IOEndpoint& other) const {
     return (!operator==(other));
 }
 
-}
+} // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/io_endpoint.h b/src/lib/asiolink/io_endpoint.h
index d21da96..756fa3b 100644
--- a/src/lib/asiolink/io_endpoint.h
+++ b/src/lib/asiolink/io_endpoint.h
@@ -26,6 +26,7 @@
 #include <exceptions/exceptions.h>
 #include <asiolink/io_address.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c IOEndpoint class is an abstract base class to represent
@@ -117,5 +118,6 @@ public:
                                     const unsigned short port);
 };
 
-}      // asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __IO_ENDPOINT_H
diff --git a/src/lib/asiolink/io_error.h b/src/lib/asiolink/io_error.h
index 2869e0b..c19d91c 100644
--- a/src/lib/asiolink/io_error.h
+++ b/src/lib/asiolink/io_error.h
@@ -18,6 +18,7 @@
 
 #include <exceptions/exceptions.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief An exception that is thrown if an error occurs within the IO
@@ -30,6 +31,7 @@ public:
 };
 
 
-}      // asiolink
+} // namespace asiolink
+} // namespace isc
 
 #endif // __IO_ERROR_H
diff --git a/src/lib/asiolink/io_fetch.cc b/src/lib/asiolink/io_fetch.cc
deleted file mode 100644
index fdc1f2e..0000000
--- a/src/lib/asiolink/io_fetch.cc
+++ /dev/null
@@ -1,380 +0,0 @@
-// Copyright (C) 2011  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.
-
-#include <config.h>
-
-#include <unistd.h>             // for some IPC/network system calls
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include <boost/bind.hpp>
-#include <boost/scoped_ptr.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
-#include <dns/message.h>
-#include <dns/messagerenderer.h>
-#include <dns/opcode.h>
-#include <dns/rcode.h>
-#include <log/logger.h>
-
-#include <asiolink/qid_gen.h>
-
-#include <asio.hpp>
-#include <asio/deadline_timer.hpp>
-
-#include <asiolink/asiodef.h>
-#include <asiolink/io_address.h>
-#include <asiolink/io_asio_socket.h>
-#include <asiolink/io_endpoint.h>
-#include <asiolink/io_fetch.h>
-#include <asiolink/io_service.h>
-#include <asiolink/tcp_endpoint.h>
-#include <asiolink/tcp_socket.h>
-#include <asiolink/udp_endpoint.h>
-#include <asiolink/udp_socket.h>
-#include <asiolink/qid_gen.h>
-
-#include <stdint.h>
-
-using namespace asio;
-using namespace isc::dns;
-using namespace isc::log;
-using namespace std;
-
-namespace asiolink {
-
-/// Use the ASIO logger
-
-isc::log::Logger logger("asiolink");
-
-/// \brief IOFetch Data
-///
-/// The data for IOFetch is held in a separate struct pointed to by a shared_ptr
-/// object.  This is because the IOFetch object will be copied often (it is used
-/// as a coroutine and passed as callback to many async_*() functions) and we
-/// want keep the same data).  Organising the data in this way keeps copying to
-/// a minimum.
-struct IOFetchData {
-
-    // The first two members are shared pointers to a base class because what is
-    // actually instantiated depends on whether the fetch is over UDP or TCP,
-    // which is not known until construction of the IOFetch.  Use of a shared
-    // pointer here is merely to ensure deletion when the data object is deleted.
-    boost::scoped_ptr<IOAsioSocket<IOFetch> > socket;
-                                             ///< Socket to use for I/O
-    boost::scoped_ptr<IOEndpoint> remote_snd;///< Where the fetch is sent
-    boost::scoped_ptr<IOEndpoint> remote_rcv;///< Where the response came from
-    isc::dns::Question          question;    ///< Question to be asked
-    isc::dns::OutputBufferPtr   msgbuf;      ///< Wire buffer for question
-    isc::dns::OutputBufferPtr   received;    ///< Received data put here
-    IOFetch::Callback*          callback;    ///< Called on I/O Completion
-    asio::deadline_timer        timer;       ///< Timer to measure timeouts
-    IOFetch::Protocol           protocol;    ///< Protocol being used
-    size_t                      cumulative;  ///< Cumulative received amount
-    size_t                      expected;    ///< Expected amount of data
-    size_t                      offset;      ///< Offset to receive data
-    bool                        stopped;     ///< Have we stopped running?
-    int                         timeout;     ///< Timeout in ms
-
-    // In case we need to log an error, the origin of the last asynchronous
-    // I/O is recorded.  To save time and simplify the code, this is recorded
-    // as the ID of the error message that would be generated if the I/O failed.
-    // This means that we must make sure that all possible "origins" take the
-    // same arguments in their message in the same order.
-    isc::log::MessageID         origin;     ///< Origin of last asynchronous I/O
-    uint8_t                     staging[IOFetch::STAGING_LENGTH];
-                                            ///< Temporary array for received data
-    isc::dns::qid_t             qid;         ///< The QID set in the query
-
-    /// \brief Constructor
-    ///
-    /// Just fills in the data members of the IOFetchData structure
-    ///
-    /// \param proto Either IOFetch::TCP or IOFetch::UDP.
-    /// \param service I/O Service object to handle the asynchronous
-    ///        operations.
-    /// \param query DNS question to send to the upstream server.
-    /// \param address IP address of upstream server
-    /// \param port Port to use for the query
-    /// \param buff Output buffer into which the response (in wire format)
-    ///        is written (if a response is received).
-    /// \param cb Callback object containing the callback to be called
-    ///        when we terminate.  The caller is responsible for managing this
-    ///        object and deleting it if necessary.
-    /// \param wait Timeout for the fetch (in ms).
-    ///
-    /// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
-    IOFetchData(IOFetch::Protocol proto, IOService& service,
-        const isc::dns::Question& query, const IOAddress& address,
-        uint16_t port, isc::dns::OutputBufferPtr& buff, IOFetch::Callback* cb,
-        int wait)
-        :
-        socket((proto == IOFetch::UDP) ?
-            static_cast<IOAsioSocket<IOFetch>*>(
-                new UDPSocket<IOFetch>(service)) :
-            static_cast<IOAsioSocket<IOFetch>*>(
-                new TCPSocket<IOFetch>(service))
-            ),
-        remote_snd((proto == IOFetch::UDP) ?
-            static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
-            static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
-            ),
-        remote_rcv((proto == IOFetch::UDP) ?
-            static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
-            static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
-            ),
-        question(query),
-        msgbuf(new isc::dns::OutputBuffer(512)),
-        received(buff),
-
-        callback(cb),
-        timer(service.get_io_service()),
-        protocol(proto),
-        cumulative(0),
-        expected(0),
-        offset(0),
-        stopped(false),
-        timeout(wait),
-        origin(ASIO_UNKORIGIN),
-        staging(),
-        qid(QidGenerator::getInstance().generateQid())
-    {}
-
-    // Checks if the response we received was ok;
-    // - data contains the buffer we read, as well as the address
-    // we sent to and the address we received from.
-    // length is provided by the operator() in IOFetch.
-    // Addresses must match, number of octets read must be at least
-    // 2, and the first two octets must match the qid of the message
-    // we sent.
-    bool responseOK() {
-        return (*remote_snd == *remote_rcv && cumulative >= 2 &&
-                readUint16(received->getData()) == qid);
-    }
-};
-
-/// IOFetch Constructor - just initialize the private data
-
-IOFetch::IOFetch(Protocol protocol, IOService& service,
-    const isc::dns::Question& question, const IOAddress& address, uint16_t port,
-    OutputBufferPtr& buff, Callback* cb, int wait)
-    :
-    data_(new IOFetchData(protocol, service, question, address,
-        port, buff, cb, wait))
-{
-}
-
-// Return protocol in use.
-
-IOFetch::Protocol
-IOFetch::getProtocol() const {
-    return (data_->protocol);
-}
-
-/// The function operator is implemented with the "stackless coroutine"
-/// pattern; see internal/coroutine.h for details.
-
-void
-IOFetch::operator()(asio::error_code ec, size_t length) {
-
-    if (data_->stopped) {
-        return;
-    } else if (ec) {
-        logIOFailure(ec);
-        return;
-    }
-
-    CORO_REENTER (this) {
-
-        /// Generate the upstream query and render it to wire format
-        /// This is done in a different scope to allow inline variable
-        /// declarations.
-        {
-            Message msg(Message::RENDER);
-            msg.setQid(data_->qid);
-            msg.setOpcode(Opcode::QUERY());
-            msg.setRcode(Rcode::NOERROR());
-            msg.setHeaderFlag(Message::HEADERFLAG_RD);
-            msg.addQuestion(data_->question);
-            MessageRenderer renderer(*data_->msgbuf);
-            msg.toWire(renderer);
-        }
-
-        // If we timeout, we stop, which will can cancel outstanding I/Os and
-        // shutdown everything.
-        if (data_->timeout != -1) {
-            data_->timer.expires_from_now(boost::posix_time::milliseconds(
-                data_->timeout));
-            data_->timer.async_wait(boost::bind(&IOFetch::stop, *this,
-                TIME_OUT));
-        }
-
-        // Open a connection to the target system.  For speed, if the operation
-        // is synchronous (i.e. UDP operation) we bypass the yield.
-        data_->origin = ASIO_OPENSOCK;
-        if (data_->socket->isOpenSynchronous()) {
-            data_->socket->open(data_->remote_snd.get(), *this);
-        } else {
-            CORO_YIELD data_->socket->open(data_->remote_snd.get(), *this);
-        }
-
-        do {
-            // Begin an asynchronous send, and then yield.  When the send completes,
-            // we will resume immediately after this point.
-            data_->origin = ASIO_SENDSOCK;
-            CORO_YIELD data_->socket->asyncSend(data_->msgbuf->getData(),
-                data_->msgbuf->getLength(), data_->remote_snd.get(), *this);
-    
-            // Now receive the response.  Since TCP may not receive the entire
-            // message in one operation, we need to loop until we have received
-            // it. (This can't be done within the asyncReceive() method because
-            // each I/O operation will be done asynchronously and between each one
-            // we need to yield ... and we *really* don't want to set up another
-            // coroutine within that method.)  So after each receive (and yield),
-            // we check if the operation is complete and if not, loop to read again.
-            //
-            // Another concession to TCP is that the amount of is contained in the
-            // first two bytes.  This leads to two problems:
-            //
-            // a) We don't want those bytes in the return buffer.
-            // b) They may not both arrive in the first I/O.
-            //
-            // So... we need to loop until we have at least two bytes, then store
-            // the expected amount of data.  Then we need to loop until we have
-            // received all the data before copying it back to the user's buffer.
-            // And we want to minimise the amount of copying...
-    
-            data_->origin = ASIO_RECVSOCK;
-            data_->cumulative = 0;          // No data yet received
-            data_->offset = 0;              // First data into start of buffer
-            data_->received->clear();       // Clear the receive buffer
-            do {
-                CORO_YIELD data_->socket->asyncReceive(data_->staging,
-                                                       static_cast<size_t>(STAGING_LENGTH),
-                                                       data_->offset,
-                                                       data_->remote_rcv.get(), *this);
-            } while (!data_->socket->processReceivedData(data_->staging, length,
-                                                         data_->cumulative, data_->offset,
-                                                         data_->expected, data_->received));
-        } while (!data_->responseOK());
-
-        // Finished with this socket, so close it.  This will not generate an
-        // I/O error, but reset the origin to unknown in case we change this.
-        data_->origin = ASIO_UNKORIGIN;
-        data_->socket->close();
-
-        /// We are done
-        stop(SUCCESS);
-    }
-}
-
-// Function that stops the coroutine sequence.  It is called either when the
-// query finishes or when the timer times out.  Either way, it sets the
-// "stopped_" flag and cancels anything that is in progress.
-//
-// As the function may be entered multiple times as things wind down, it checks
-// if the stopped_ flag is already set.  If it is, the call is a no-op.
-
-void
-IOFetch::stop(Result result) {
-
-    if (!data_->stopped) {
-
-        // Mark the fetch as stopped to prevent other completion callbacks
-        // (invoked because of the calls to cancel()) from executing the
-        // cancel calls again.
-        //
-        // In a single threaded environment, the callbacks won't be invoked
-        // until this one completes. In a multi-threaded environment, they may
-        // well be, in which case the testing (and setting) of the stopped_
-        // variable should be done inside a mutex (and the stopped_ variable
-        // declared as "volatile").
-        //
-        // The numeric arguments indicate the debug level, with the lower
-        // numbers indicating the most important information.  The relative
-        // values are somewhat arbitrary.
-        //
-        // Although Logger::debug checks the debug flag internally, doing it
-        // below before calling Logger::debug avoids the overhead of a string
-        // conversion in the common case when debug is not enabled.
-        //
-        // TODO: Update testing of stopped_ if threads are used.
-        data_->stopped = true;
-        switch (result) {
-            case TIME_OUT:
-                if (logger.isDebugEnabled(1)) {
-                    logger.debug(20, ASIO_RECVTMO,
-                                 data_->remote_snd->getAddress().toText().c_str(),
-                                 static_cast<int>(data_->remote_snd->getPort()));
-                }
-                break;
-
-            case SUCCESS:
-                if (logger.isDebugEnabled(50)) {
-                    logger.debug(30, ASIO_FETCHCOMP,
-                                 data_->remote_rcv->getAddress().toText().c_str(),
-                                 static_cast<int>(data_->remote_rcv->getPort()));
-                }
-                break;
-
-            case STOPPED:
-                // Fetch has been stopped for some other reason.  This is
-                // allowed but as it is unusual it is logged, but with a lower
-                // debug level than a timeout (which is totally normal).
-                logger.debug(1, ASIO_FETCHSTOP,
-                             data_->remote_snd->getAddress().toText().c_str(),
-                             static_cast<int>(data_->remote_snd->getPort()));
-                break;
-
-            default:
-                logger.error(ASIO_UNKRESULT, static_cast<int>(result),
-                             data_->remote_snd->getAddress().toText().c_str(),
-                             static_cast<int>(data_->remote_snd->getPort()));
-        }
-
-        // Stop requested, cancel and I/O's on the socket and shut it down,
-        // and cancel the timer.
-        data_->socket->cancel();
-        data_->socket->close();
-
-        data_->timer.cancel();
-
-        // Execute the I/O completion callback (if present).
-        if (data_->callback) {
-            (*(data_->callback))(result);
-        }
-    }
-}
-
-// Log an error - called on I/O failure
-
-void IOFetch::logIOFailure(asio::error_code ec) {
-
-    // Should only get here with a known error code.
-    assert((data_->origin == ASIO_OPENSOCK) ||
-           (data_->origin == ASIO_SENDSOCK) ||
-           (data_->origin == ASIO_RECVSOCK) ||
-           (data_->origin == ASIO_UNKORIGIN));
-
-    static const char* PROTOCOL[2] = {"TCP", "UDP"};
-    logger.error(data_->origin,
-                 ec.value(),
-                 ((data_->remote_snd->getProtocol() == IPPROTO_TCP) ?
-                     PROTOCOL[0] : PROTOCOL[1]),
-                 data_->remote_snd->getAddress().toText().c_str(),
-                 static_cast<int>(data_->remote_snd->getPort()));
-}
-
-} // namespace asiolink
-
diff --git a/src/lib/asiolink/io_fetch.h b/src/lib/asiolink/io_fetch.h
deleted file mode 100644
index 0723777..0000000
--- a/src/lib/asiolink/io_fetch.h
+++ /dev/null
@@ -1,179 +0,0 @@
-// 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.
-
-#ifndef __IO_FETCH_H
-#define __IO_FETCH_H 1
-
-#include <config.h>
-
-#include <boost/shared_array.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
-#include <coroutine.h>
-
-#include <asio/error_code.hpp>
-
-#include <dns/buffer.h>
-#include <dns/question.h>
-
-namespace asiolink {
-
-// Forward declarations
-class IOAddress;
-class IOFetchData;
-class IOService;
-
-/// \brief Upstream Fetch Processing
-///
-/// IOFetch is the class used to send upstream fetches and to handle responses.
-///
-/// \param E Endpoint type to use.
-
-class IOFetch : public coroutine {
-public:
-    /// \brief Protocol to use on the fetch
-    enum Protocol {
-        UDP = 0,
-        TCP = 1
-    };
-
-    /// \brief Origin of Asynchronous I/O Call
-    ///
-    /// Indicates what initiated an asynchronous I/O call and used in deciding
-    /// what error message to output if the I/O fails.
-    enum Origin {
-        NONE = 0,           ///< No asynchronous call outstanding
-        OPEN = 1,
-        SEND = 2,
-        RECEIVE = 3,
-        CLOSE = 4
-    };
-
-    /// \brief Result of Upstream Fetch
-    ///
-    /// Note that this applies to the status of I/Os in the fetch - a fetch
-    /// that resulted in a packet being received from the server is a SUCCESS,
-    /// even if the contents of the packet indicate that some error occurred.
-    enum Result {
-        SUCCESS = 0,        ///< Success, fetch completed
-        TIME_OUT = 1,       ///< Failure, fetch timed out
-        STOPPED = 2,        ///< Control code, fetch has been stopped
-        NOTSET = 3          ///< For testing, indicates value not set
-    };
-
-    // The next enum is a "trick" to allow constants to be defined in a class
-    // declaration.
-
-    /// \brief Integer Constants
-    enum {
-        STAGING_LENGTH = 8192   ///< Size of staging buffer
-    };
-
-    /// \brief I/O Fetch Callback
-    ///
-    /// Class of callback object for when the fetch itself has completed - an
-    /// object of this class is passed to the IOFetch constructor and its
-    /// operator() method called when the fetch completes.
-    ///
-    /// Note the difference between the two operator() methods:
-    /// - IOFetch::operator() callback is called when an asynchronous I/O has
-    ///   completed.
-    /// - IOFetch::Callback::operator() is called when an upstream fetch - which
-    ///   may have involved several asynchronous I/O operations - has completed.
-    ///
-    /// This is an abstract class.
-    class Callback {
-    public:
-        /// \brief Default Constructor
-        Callback()
-        {}
-
-        /// \brief Virtual Destructor
-        virtual ~Callback()
-        {}
-
-        /// \brief Callback method
-        ///
-        /// This is the method called when the fetch completes.
-        ///
-        /// \param result Result of the fetch
-        virtual void operator()(Result result) = 0;
-    };
-
-    /// \brief Constructor.
-    ///
-    /// Creates the object that will handle the upstream fetch.
-    ///
-    /// TODO: Need to randomise the source port
-    ///
-    /// \param protocol Fetch protocol, either IOFetch::TCP or IOFetch::UDP
-    /// \param service I/O Service object to handle the asynchronous
-    ///     operations.
-    /// \param question DNS question to send to the upstream server.
-    /// \param buff Output buffer into which the response (in wire format)
-    ///     is written (if a response is received).
-    /// \param cb Callback object containing the callback to be called
-    ///     when we terminate.  The caller is responsible for managing this
-    ///     object and deleting it if necessary.
-    /// \param address IP address of upstream server
-    /// \param port Port to which to connect on the upstream server
-    /// (default = 53)
-    /// \param wait Timeout for the fetch (in ms).  The default value of
-    ///     -1 indicates no timeout.
-    IOFetch(Protocol protocol, IOService& service,
-        const isc::dns::Question& question, const IOAddress& address,
-        uint16_t port, isc::dns::OutputBufferPtr& buff, Callback* cb,
-        int wait = -1);
-
-    /// \brief Return Current Protocol
-    ///
-    /// \return Protocol associated with this IOFetch object.
-    Protocol getProtocol() const;
-
-    /// \brief Coroutine entry point
-    ///
-    /// The operator() method is the method in which the coroutine code enters
-    /// this object when an operation has been completed.
-    ///
-    /// \param ec Error code, the result of the last asynchronous I/O operation.
-    /// \param length Amount of data received on the last asynchronous read
-    void operator()(asio::error_code ec = asio::error_code(), size_t length = 0);
-
-    /// \brief Terminate query
-    ///
-    /// This method can be called at any point.  It terminates the current
-    /// query with the specified reason.
-    ///
-    /// \param reason Reason for terminating the query
-    void stop(Result reason = STOPPED);
-
-private:
-    /// \brief Log I/O Failure
-    ///
-    /// Records an I/O failure to the log file
-    ///
-    /// \param ec ASIO error code
-    void logIOFailure(asio::error_code ec);
-
-    // Member variables.  All data is in a structure pointed to by a shared
-    // pointer.  The IOFetch object is copied a number of times during its
-    // life, and only requiring a pointer to be copied reduces overhead.
-    boost::shared_ptr<IOFetchData>  data_;   ///< Private data
-
-};
-
-} // namespace asiolink
-
-#endif // __IO_FETCH_H
diff --git a/src/lib/asiolink/io_message.h b/src/lib/asiolink/io_message.h
index e857bd9..81f6da1 100644
--- a/src/lib/asiolink/io_message.h
+++ b/src/lib/asiolink/io_message.h
@@ -28,6 +28,7 @@
 #include <asiolink/io_endpoint.h>
 #include <asiolink/io_socket.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c IOMessage class encapsulates an incoming message received
@@ -96,5 +97,6 @@ private:
 };
 
 
-}      // asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __IO_MESSAGE_H
diff --git a/src/lib/asiolink/io_service.cc b/src/lib/asiolink/io_service.cc
index 55fc4b3..70cc18b 100644
--- a/src/lib/asiolink/io_service.cc
+++ b/src/lib/asiolink/io_service.cc
@@ -21,6 +21,7 @@
 #include <asio.hpp>
 #include <asiolink/io_service.h>
 
+namespace isc {
 namespace asiolink {
 
 class IOServiceImpl {
@@ -95,4 +96,5 @@ IOService::get_io_service() {
     return (io_impl_->get_io_service());
 }
 
-} // namepsace asiolink
+} // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/io_service.h b/src/lib/asiolink/io_service.h
index 66558b7..438667c 100644
--- a/src/lib/asiolink/io_service.h
+++ b/src/lib/asiolink/io_service.h
@@ -19,6 +19,7 @@ namespace asio {
     class io_service;
 }
 
+namespace isc {
 namespace asiolink {
 
 struct IOServiceImpl;
@@ -73,5 +74,6 @@ private:
     IOServiceImpl* io_impl_;
 };
 
-}      // namespace asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __ASIOLINK_IO_SERVICE_H
diff --git a/src/lib/asiolink/io_socket.cc b/src/lib/asiolink/io_socket.cc
index c386ca1..e1498dc 100644
--- a/src/lib/asiolink/io_socket.cc
+++ b/src/lib/asiolink/io_socket.cc
@@ -16,8 +16,7 @@
 
 #include <asio.hpp>
 
-using namespace asio;
-
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c DummySocket class is a concrete derived class of
@@ -62,4 +61,5 @@ IOSocket::getDummyTCPSocket() {
     return (socket);
 }
 
-}
+} // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/io_socket.h b/src/lib/asiolink/io_socket.h
index bebc8b6..ab6479c 100644
--- a/src/lib/asiolink/io_socket.h
+++ b/src/lib/asiolink/io_socket.h
@@ -25,6 +25,7 @@
 
 #include <exceptions/exceptions.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c IOSocket class is an abstract base class to represent
@@ -120,5 +121,6 @@ public:
 };
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __IO_SOCKET_H
diff --git a/src/lib/asiolink/qid_gen.cc b/src/lib/asiolink/qid_gen.cc
index 4063b39..7088a11 100644
--- a/src/lib/asiolink/qid_gen.cc
+++ b/src/lib/asiolink/qid_gen.cc
@@ -23,9 +23,10 @@
 #include <sys/time.h>
 
 namespace {
-    asiolink::QidGenerator qid_generator_instance;
+    isc::asiolink::QidGenerator qid_generator_instance;
 }
 
+namespace isc {
 namespace asiolink {
 
 QidGenerator&
@@ -52,3 +53,4 @@ QidGenerator::generateQid() {
 }
 
 } // namespace asiolink
+} // namespace isc
diff --git a/src/lib/asiolink/qid_gen.h b/src/lib/asiolink/qid_gen.h
index a5caa17..466e78f 100644
--- a/src/lib/asiolink/qid_gen.h
+++ b/src/lib/asiolink/qid_gen.h
@@ -27,6 +27,7 @@
 #include <boost/random/variate_generator.hpp>
 
 
+namespace isc {
 namespace asiolink {
 
 /// This class generates Qids for outgoing queries
@@ -81,5 +82,6 @@ private:
 
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __QID_GEN_H
diff --git a/src/lib/asiolink/simple_callback.h b/src/lib/asiolink/simple_callback.h
index ab5deaf..92093ec 100644
--- a/src/lib/asiolink/simple_callback.h
+++ b/src/lib/asiolink/simple_callback.h
@@ -17,6 +17,7 @@
 
 #include <asiolink/io_message.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c SimpleCallback class is an abstract base class for a
@@ -67,5 +68,6 @@ private:
     SimpleCallback* self_;
 };
 
-}      // namespace asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __ASIOLINK_SIMPLE_CALLBACK_H
diff --git a/src/lib/asiolink/tcp_endpoint.h b/src/lib/asiolink/tcp_endpoint.h
index 158ca4a..3e420f3 100644
--- a/src/lib/asiolink/tcp_endpoint.h
+++ b/src/lib/asiolink/tcp_endpoint.h
@@ -21,6 +21,7 @@
 
 #include <asiolink/io_endpoint.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c TCPEndpoint class is a concrete derived class of
@@ -109,5 +110,6 @@ private:
     asio::ip::tcp::endpoint& asio_endpoint_;
 };
 
-}      // namespace asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __TCP_ENDPOINT_H
diff --git a/src/lib/asiolink/tcp_socket.h b/src/lib/asiolink/tcp_socket.h
index e6e0863..bf1e909 100644
--- a/src/lib/asiolink/tcp_socket.h
+++ b/src/lib/asiolink/tcp_socket.h
@@ -41,6 +41,7 @@
 #include <asiolink/io_service.h>
 #include <asiolink/tcp_endpoint.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief Buffer Too Large
@@ -412,5 +413,6 @@ TCPSocket<C>::close() {
 }
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __TCP_SOCKET_H
diff --git a/src/lib/asiolink/tests/Makefile.am b/src/lib/asiolink/tests/Makefile.am
index d52e8bf..cec9d4d 100644
--- a/src/lib/asiolink/tests/Makefile.am
+++ b/src/lib/asiolink/tests/Makefile.am
@@ -21,7 +21,6 @@ run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc
 run_unittests_SOURCES += asiolink_utilities_unittest.cc
 run_unittests_SOURCES += io_address_unittest.cc
 run_unittests_SOURCES += io_endpoint_unittest.cc
-run_unittests_SOURCES += io_fetch_unittest.cc
 run_unittests_SOURCES += io_socket_unittest.cc
 run_unittests_SOURCES += interval_timer_unittest.cc
 run_unittests_SOURCES += tcp_endpoint_unittest.cc
diff --git a/src/lib/asiolink/tests/asiolink_utilities_unittest.cc b/src/lib/asiolink/tests/asiolink_utilities_unittest.cc
index 51f565f..369b0f9 100644
--- a/src/lib/asiolink/tests/asiolink_utilities_unittest.cc
+++ b/src/lib/asiolink/tests/asiolink_utilities_unittest.cc
@@ -24,7 +24,7 @@
 #include <dns/buffer.h>
 #include <asiolink/asiolink_utilities.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 using namespace isc::dns;
 
 TEST(asioutil, readUint16) {
diff --git a/src/lib/asiolink/tests/interval_timer_unittest.cc b/src/lib/asiolink/tests/interval_timer_unittest.cc
index 7e0e7bc..c24e60e 100644
--- a/src/lib/asiolink/tests/interval_timer_unittest.cc
+++ b/src/lib/asiolink/tests/interval_timer_unittest.cc
@@ -26,7 +26,7 @@ const boost::posix_time::time_duration TIMER_MARGIN_MSEC =
     boost::posix_time::milliseconds(50);
 }
 
-using namespace asiolink;
+using namespace isc::asiolink;
 
 // This fixture is for testing IntervalTimer. Some callback functors are 
 // registered as callback function of the timer to test if they are called
diff --git a/src/lib/asiolink/tests/io_address_unittest.cc b/src/lib/asiolink/tests/io_address_unittest.cc
index 894f143..18b181e 100644
--- a/src/lib/asiolink/tests/io_address_unittest.cc
+++ b/src/lib/asiolink/tests/io_address_unittest.cc
@@ -18,7 +18,7 @@
 #include <asiolink/io_error.h>
 #include <asiolink/io_address.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 
 TEST(IOAddressTest, fromText) {
     IOAddress io_address_v4("192.0.2.1");
diff --git a/src/lib/asiolink/tests/io_endpoint_unittest.cc b/src/lib/asiolink/tests/io_endpoint_unittest.cc
index 5170f7d..ce21fde 100644
--- a/src/lib/asiolink/tests/io_endpoint_unittest.cc
+++ b/src/lib/asiolink/tests/io_endpoint_unittest.cc
@@ -18,7 +18,7 @@
 #include <asiolink/io_endpoint.h>
 #include <asiolink/io_error.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 
 TEST(IOEndpointTest, createUDPv4) {
     const IOEndpoint* ep;
diff --git a/src/lib/asiolink/tests/io_fetch_unittest.cc b/src/lib/asiolink/tests/io_fetch_unittest.cc
deleted file mode 100644
index 2b258b8..0000000
--- a/src/lib/asiolink/tests/io_fetch_unittest.cc
+++ /dev/null
@@ -1,723 +0,0 @@
-// Copyright (C) 2011  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.
-
-#include <algorithm>
-#include <cstdlib>
-#include <string>
-#include <iostream>
-#include <iomanip>
-#include <iterator>
-#include <vector>
-
-#include <gtest/gtest.h>
-#include <boost/bind.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
-#include <asio.hpp>
-
-#include <dns/buffer.h>
-#include <dns/question.h>
-#include <dns/message.h>
-#include <dns/messagerenderer.h>
-#include <dns/opcode.h>
-#include <dns/name.h>
-#include <dns/rcode.h>
-
-#include <asiolink/asiolink_utilities.h>
-#include <asiolink/io_address.h>
-#include <asiolink/io_endpoint.h>
-#include <asiolink/io_fetch.h>
-#include <asiolink/io_service.h>
-
-using namespace asio;
-using namespace isc::dns;
-using namespace asio::ip;
-using namespace std;
-
-namespace asiolink {
-
-const asio::ip::address TEST_HOST(asio::ip::address::from_string("127.0.0.1"));
-const uint16_t TEST_PORT(5301);
-const int SEND_INTERVAL = 250;      // Interval in ms between TCP sends
-const size_t MAX_SIZE = 64 * 1024;  // Should be able to take 64kB
-
-// The tests are complex, so debug output has been left in (although disabled).
-// Set this to true to enable it.
-const bool DEBUG = false;
-
-/// \brief Test fixture for the asiolink::IOFetch.
-class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Callback
-{
-public:
-    IOService       service_;       ///< Service to run the query
-    IOFetch::Result expected_;      ///< Expected result of the callback
-    bool            run_;           ///< Did the callback run already?
-    Question        question_;      ///< What to ask
-    OutputBufferPtr result_buff_;   ///< Buffer to hold result of fetch
-    OutputBufferPtr msgbuf_;        ///< Buffer corresponding to known question
-    IOFetch         udp_fetch_;     ///< For UDP query test
-    IOFetch         tcp_fetch_;     ///< For TCP query test
-    IOFetch::Protocol protocol_;    ///< Protocol being tested
-    size_t          cumulative_;    ///< Cumulative data received by "server".
-    deadline_timer  timer_;         ///< Timer to measure timeouts
-
-    // The next member is the buffer in which the "server" (implemented by the
-    // response handler methods in this class) receives the question sent by the
-    // fetch object.
-    uint8_t         receive_buffer_[MAX_SIZE]; ///< Server receive buffer
-    OutputBufferPtr expected_buffer_;          ///< Data we expect to receive
-    vector<uint8_t> send_buffer_;           ///< Server send buffer
-    uint16_t        send_cumulative_;       ///< Data sent so far
-
-    // Other data.
-    string          return_data_;           ///< Data returned by server
-    string          test_data_;             ///< Large string - here for convenience
-    bool            debug_;                 ///< true to enable debug output
-    size_t          tcp_send_size_;         ///< Max size of TCP send
-    uint8_t         qid_0;                  ///< First octet of qid
-    uint8_t         qid_1;                  ///< Second octet of qid
-
-    bool            tcp_short_send_;        ///< If set to true, we do not send
-                                            ///  all data in the tcp response
-
-    /// \brief Constructor
-    IOFetchTest() :
-        service_(),
-        expected_(IOFetch::NOTSET),
-        run_(false),
-        question_(Name("example.net"), RRClass::IN(), RRType::A()),
-        result_buff_(new OutputBuffer(512)),
-        msgbuf_(new OutputBuffer(512)),
-        udp_fetch_(IOFetch::UDP, service_, question_, IOAddress(TEST_HOST),
-            TEST_PORT, result_buff_, this, 100),
-        tcp_fetch_(IOFetch::TCP, service_, question_, IOAddress(TEST_HOST),
-            TEST_PORT, result_buff_, this, (16 * SEND_INTERVAL)),
-                                        // Timeout interval chosen to ensure no timeout
-        protocol_(IOFetch::TCP),        // for initialization - will be changed
-        cumulative_(0),
-        timer_(service_.get_io_service()),
-        receive_buffer_(),
-        expected_buffer_(new OutputBuffer(512)),
-        send_buffer_(),
-        send_cumulative_(0),
-        return_data_(""),
-        test_data_(""),
-        debug_(DEBUG),
-        tcp_send_size_(0),
-        qid_0(0),
-        qid_1(0),
-        tcp_short_send_(false)
-    {
-        // Construct the data buffer for question we expect to receive.
-        Message msg(Message::RENDER);
-        msg.setQid(0);
-        msg.setOpcode(Opcode::QUERY());
-        msg.setRcode(Rcode::NOERROR());
-        msg.setHeaderFlag(Message::HEADERFLAG_RD);
-        msg.addQuestion(question_);
-        MessageRenderer renderer(*msgbuf_);
-        msg.toWire(renderer);
-        MessageRenderer renderer2(*expected_buffer_);
-        msg.toWire(renderer2);
-
-        // Initialize the test data to be returned: tests will return a
-        // substring of this data. (It's convenient to have this as a member of
-        // the class.)
-        //
-        // We could initialize the data with a single character, but as an added
-        // check we'll make ssre that it has some structure.
-
-        test_data_.clear();
-        test_data_.reserve(MAX_SIZE);
-        while (test_data_.size() < MAX_SIZE) {
-            test_data_ += "A message to be returned to the client that has "
-                          "some sort of structure.";
-        }
-    }
-
-    /// \brief UDP Response handler (the "remote UDP DNS server")
-    ///
-    /// When IOFetch is sending data, this response handler emulates the remote
-    /// DNS server.  It checks that the data sent by the IOFetch object is what
-    /// was expected to have been sent, then sends back a known buffer of data.
-    ///
-    /// \param remote Endpoint to which to send the answer
-    /// \param socket Socket to use to send the answer
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param bad_qid If set to true, the QID in the response will be mangled
-    /// \param second_send If set to true, (and bad_qid is too), after the
-    ///        mangled qid response has been sent, a second packet will be
-    ///        sent with the correct QID.
-    /// \param length Amount of data received.
-    void udpReceiveHandler(udp::endpoint* remote, udp::socket* socket,
-                    error_code ec = error_code(), size_t length = 0,
-                    bool bad_qid = false, bool second_send = false) {
-        if (debug_) {
-            cout << "udpReceiveHandler(): error = " << ec.value() <<
-                    ", length = " << length << endl;
-        }
-
-        // The QID in the incoming data is random so set it to 0 for the
-        // data comparison check. (It is set to 0 in the buffer containing
-        // the expected data.)
-        qid_0 = receive_buffer_[0];
-        qid_1 = receive_buffer_[1];
-        receive_buffer_[0] = receive_buffer_[1] = 0;
-
-        // Check that length of the received data and the expected data are
-        // identical, then check that the data is identical as well.
-        EXPECT_EQ(msgbuf_->getLength(), length);
-        EXPECT_TRUE(equal(receive_buffer_, (receive_buffer_ + length - 1),
-        static_cast<const uint8_t*>(msgbuf_->getData())));
-
-        // Return a message back to the IOFetch object.
-        if (!bad_qid) {
-            expected_buffer_->writeUint8At(qid_0, 0);
-            expected_buffer_->writeUint8At(qid_1, 1);
-        } else {
-            expected_buffer_->writeUint8At(qid_0 + 1, 0);
-            expected_buffer_->writeUint8At(qid_1 + 1, 1);
-        }
-        socket->send_to(asio::buffer(expected_buffer_->getData(), length), *remote);
-
-        if (bad_qid && second_send) {
-            expected_buffer_->writeUint8At(qid_0, 0);
-            expected_buffer_->writeUint8At(qid_1, 1);
-            socket->send_to(asio::buffer(expected_buffer_->getData(),
-                            expected_buffer_->getLength()), *remote);
-        }
-        if (debug_) {
-            cout << "udpReceiveHandler(): returned " << expected_buffer_->getLength() <<
-                    " bytes to the client" << endl;
-        }
-    }
-
-    /// \brief Completion Handler for accepting TCP data
-    ///
-    /// Called when the remote system connects to the "server".  It issues
-    /// an asynchronous read on the socket to read data.
-    ///
-    /// \param socket Socket on which data will be received
-    /// \param ec Boost error code, value should be zero.
-    void tcpAcceptHandler(tcp::socket* socket, error_code ec = error_code())
-    {
-        if (debug_) {
-            cout << "tcpAcceptHandler(): error = " << ec.value() << endl;
-        }
-
-        // Expect that the accept completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // Work out the maximum size of data we can send over it when we
-        // respond, then subtract 1kB or so for safety.
-        tcp::socket::send_buffer_size send_size;
-        socket->get_option(send_size);
-        if (send_size.value() < (2 * 1024)) {
-            FAIL() << "TCP send size is less than 2kB";
-        } else {
-            tcp_send_size_ = send_size.value() - 1024;
-            if (debug_) {
-                cout << "tcpacceptHandler(): will use send size = " << tcp_send_size_ << endl;
-            }
-        }
-
-        // Initiate a read on the socket.
-        cumulative_ = 0;
-        socket->async_receive(asio::buffer(receive_buffer_, sizeof(receive_buffer_)),
-            boost::bind(&IOFetchTest::tcpReceiveHandler, this, socket, _1, _2));
-    }
-
-    /// \brief Completion handler for receiving TCP data
-    ///
-    /// When IOFetch is sending data, this response handler emulates the remote
-    /// DNS server.  It that all the data sent by the IOFetch object has been
-    /// received, issuing another read if not.  If the data is complete, it is
-    /// compared to what is expected and a reply sent back to the IOFetch.
-    ///
-    /// \param socket Socket to use to send the answer
-    /// \param ec ASIO error code, completion code of asynchronous I/O issued
-    ///        by the "server" to receive data.
-    /// \param length Amount of data received.
-    void tcpReceiveHandler(tcp::socket* socket, error_code ec = error_code(),
-                           size_t length = 0)
-    {
-        if (debug_) {
-            cout << "tcpReceiveHandler(): error = " << ec.value() <<
-                    ", length = " << length << endl;
-        }
-        // Expect that the receive completed without a problem.
-        EXPECT_EQ(0, ec.value());
-
-        // If we haven't received all the data, issue another read.
-        cumulative_ += length;
-        bool complete = false;
-        if (cumulative_ > 2) {
-            uint16_t dns_length = readUint16(receive_buffer_);
-            complete = ((dns_length + 2) == cumulative_);
-        }
-
-        if (!complete) {
-            socket->async_receive(asio::buffer((receive_buffer_ + cumulative_),
-                (sizeof(receive_buffer_) - cumulative_)),
-                boost::bind(&IOFetchTest::tcpReceiveHandler, this, socket, _1, _2));
-            return;
-        }
-
-        // Check that length of the DNS message received is that expected, then
-        // compare buffers, zeroing the QID in the received buffer to match
-        // that set in our expected question.  Note that due to the length
-        // field the QID in the received buffer is in the third and fourth
-        // bytes.
-        EXPECT_EQ(msgbuf_->getLength() + 2, cumulative_);
-        qid_0 = receive_buffer_[2];
-        qid_1 = receive_buffer_[3];
-
-        receive_buffer_[2] = receive_buffer_[3] = 0;
-        EXPECT_TRUE(equal((receive_buffer_ + 2), (receive_buffer_ + cumulative_ - 2),
-            static_cast<const uint8_t*>(msgbuf_->getData())));
-
-        // ... and return a message back.  This has to be preceded by a two-byte
-        // count field.
-
-        send_buffer_.clear();
-        send_buffer_.push_back(0);
-        send_buffer_.push_back(0);
-        writeUint16(return_data_.size(), &send_buffer_[0]);
-        copy(return_data_.begin(), return_data_.end(), back_inserter(send_buffer_));
-        if (return_data_.size() >= 2) {
-            send_buffer_[2] = qid_0;
-            send_buffer_[3] = qid_1;
-        }
-        // Send the data.  This is done in multiple writes with a delay between
-        // each to check that the reassembly of TCP packets from fragments works.
-        send_cumulative_ = 0;
-        tcpSendData(socket);
-    }
-
-    /// \brief Sent Data Over TCP
-    ///
-    /// Send the TCP data back to the IOFetch object.  The data is sent in
-    /// three chunks - two of 16 bytes and the remainder, with a 250ms gap
-    /// between each. (Amounts of data smaller than one 32 bytes are sent in
-    /// one or two packets.)
-    ///
-    /// \param socket Socket over which send should take place
-    void tcpSendData(tcp::socket* socket) {
-        if (debug_) {
-            cout << "tcpSendData()" << endl;
-        }
-
-        // Decide what to send based on the cumulative count.  At most we'll do
-        // two chunks of 16 bytes (with a 250ms gap between) and then the
-        // remainder.
-        uint8_t* send_ptr = &send_buffer_[send_cumulative_];
-                                    // Pointer to data to send
-        size_t amount = 16;         // Amount of data to send
-        if (send_cumulative_ < (2 * amount)) {
-            
-            // First or second time through, send at most 16 bytes
-            amount = min(amount, (send_buffer_.size() - send_cumulative_));
-
-        } else {
-
-            // For all subsequent times, send the remainder, maximised to
-            // whatever we have chosen for the maximum send size.
-            amount = min(tcp_send_size_,
-                        (send_buffer_.size() - send_cumulative_));
-        }
-
-        // This is for the short send test; reduce the actual amount of
-        // data we send
-        if (tcp_short_send_) {
-            if (debug_) {
-                cout << "tcpSendData(): sending incomplete data (" <<
-                        (amount - 1) << " of " << amount << " bytes)" <<
-                        endl;
-            }
-            --amount;
-        } else {
-            if (debug_) {
-                cout << "tcpSendData(): sending " << amount << " bytes" << endl;
-            }
-        }
-
-        // ... and send it.  The amount sent is also passed as the first
-        // argument of the send callback, as a check.
-        socket->async_send(asio::buffer(send_ptr, amount),
-                           boost::bind(&IOFetchTest::tcpSendHandler, this,
-                                       amount, socket, _1, _2));
-    }
-
-    /// \brief Completion Handler for Sending TCP data
-    ///
-    /// Called when the asynchronous send of data back to the IOFetch object
-    /// by the TCP "server" in this class has completed.  (This send has to
-    /// be asynchronous because control needs to return to the caller in order
-    /// for the IOService "run()" method to be called to run the handlers.)
-    ///
-    /// If not all the data has been sent, a short delay is instigated (during
-    /// which control returns to the IOService).  This should force the queued
-    /// data to actually be sent and the IOFetch receive handler to be triggered.
-    /// In this way, the ability of IOFetch to handle fragmented TCP packets
-    /// should be checked.
-    ///
-    /// \param expected Number of bytes that were expected to have been sent.
-    /// \param socket Socket over which the send took place.  Only used to
-    ///        pass back to the send method.
-    /// \param ec Boost error code, value should be zero.
-    /// \param length Number of bytes sent.
-    void tcpSendHandler(size_t expected, tcp::socket* socket,
-                        error_code ec = error_code(), size_t length = 0)
-    {
-        if (debug_) {
-            cout << "tcpSendHandler(): error = " << ec.value() <<
-                    ", length = " << length << endl;
-        }
-
-        EXPECT_EQ(0, ec.value());       // Expect no error
-        EXPECT_EQ(expected, length);    // And that amount sent is as expected
-
-        // Do we need to send more?
-        send_cumulative_ += length;
-        if (send_cumulative_ < send_buffer_.size()) {
-
-            // Yes - set up a timer:  the callback handler for the timer is
-            // tcpSendData, which will then send the next chunk.  We pass the
-            // socket over which data should be sent as an argument to that
-            // function.
-            timer_.expires_from_now(boost::posix_time::milliseconds(SEND_INTERVAL));
-            timer_.async_wait(boost::bind(&IOFetchTest::tcpSendData, this,
-                                          socket));
-        }
-    }
-
-    /// \brief Fetch completion callback
-    ///
-    /// This is the callback's operator() method which is called when the fetch
-    /// is complete.  It checks that the data received is the wire format of the
-    /// data sent back by the server.
-    ///
-    /// \param result Result indicated by the callback
-    void operator()(IOFetch::Result result) {
-        if (debug_) {
-            cout << "operator()(): result = " << result << endl;
-        }
-
-        EXPECT_EQ(expected_, result);   // Check correct result returned
-        EXPECT_FALSE(run_);             // Check it is run only once
-        run_ = true;                    // Note success
-
-        // If the expected result for SUCCESS, then this should have been called
-        // when one of the "servers" in this class has sent back return_data_.
-        // Check the data is as expected/
-        if (expected_ == IOFetch::SUCCESS) {
-            // In the case of UDP, we actually send back a real looking packet
-            // in the case of TCP, we send back a 'random' string
-            if (protocol_ == IOFetch::UDP) {
-                EXPECT_EQ(expected_buffer_->getLength(), result_buff_->getLength());
-                EXPECT_EQ(0, memcmp(expected_buffer_->getData(), result_buff_->getData(),
-                          expected_buffer_->getLength()));
-            } else {
-                EXPECT_EQ(return_data_.size(), result_buff_->getLength());
-                // Overwrite the random qid with our own data for the
-                // comparison to succeed
-                if (result_buff_->getLength() >= 2) {
-                    result_buff_->writeUint8At(return_data_[0], 0);
-                    result_buff_->writeUint8At(return_data_[1], 1);
-                }
-                const uint8_t* start = static_cast<const uint8_t*>(result_buff_->getData());
-                EXPECT_TRUE(equal(return_data_.begin(), return_data_.end(), start));
-            }
-        }
-
-        // ... and cause the run loop to exit.
-        service_.stop();
-    }
-
-    // The next set of methods are the tests themselves.  A number of the TCP
-    // and UDP tests are very similar.
-
-    /// \brief Check for stop()
-    ///
-    /// Test that when we run the query and stop it after it was run, it returns
-    /// "stopped" correctly. (That is why stop() is posted to the service_ as
-    /// well instead of calling it.)
-    ///
-    /// \param protocol Test protocol
-    /// \param fetch Fetch object being tested
-    void stopTest(IOFetch::Protocol protocol, IOFetch& fetch) {
-        protocol_ = protocol;
-        expected_ = IOFetch::STOPPED;
-
-        // Post the query
-        service_.get_io_service().post(fetch);
-
-        // Post query_.stop() (yes, the boost::bind thing is just
-        // query_.stop()).
-        service_.get_io_service().post(
-            boost::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
-
-        // Run both of them.  run() returns when everything in the I/O service
-        // queue has completed.
-        service_.run();
-        EXPECT_TRUE(run_);
-    }
-
-    /// \brief Premature stop test
-    ///
-    /// Test that when we queue the query to service_ and call stop() before it
-    /// gets executed, it acts sanely as well (eg. has the same result as
-    /// running stop() after - calls the callback).
-    ///
-    /// \param protocol Test protocol
-    /// \param fetch Fetch object being tested
-    void prematureStopTest(IOFetch::Protocol protocol, IOFetch& fetch) {
-        protocol_ = protocol;
-        expected_ = IOFetch::STOPPED;
-
-        // Stop before it is started
-        fetch.stop();
-        service_.get_io_service().post(fetch);
-
-        service_.run();
-        EXPECT_TRUE(run_);
-    }
-
-    /// \brief Timeout test
-    ///
-    /// Test that fetch times out when no answer arrives.
-    ///
-    /// \param protocol Test protocol
-    /// \param fetch Fetch object being tested
-    void timeoutTest(IOFetch::Protocol protocol, IOFetch& fetch) {
-        protocol_ = protocol;
-        expected_ = IOFetch::TIME_OUT;
-
-        service_.get_io_service().post(fetch);
-        service_.run();
-        EXPECT_TRUE(run_);
-    }
-
-    /// \brief Send/Receive Test
-    ///
-    /// Send a query to the server then receives a response.
-    ///
-    /// \param Test data to return to client
-    /// \param short_send If true, do not send all data
-    ///                   (should result in timeout)
-    void tcpSendReturnTest(const std::string& return_data, bool short_send = false) {
-        if (debug_) {
-            cout << "tcpSendReturnTest(): data size = " << return_data.size() << endl;
-        }
-        return_data_ = return_data;
-        protocol_ = IOFetch::TCP;
-        if (short_send) {
-            tcp_short_send_ = true;
-            expected_ = IOFetch::TIME_OUT;
-        } else {
-            expected_ = IOFetch::SUCCESS;
-        }
-
-        // Socket into which the connection will be accepted.
-        tcp::socket socket(service_.get_io_service());
-
-        // Acceptor object - called when the connection is made, the handler
-        // will initiate a read on the socket.
-        tcp::acceptor acceptor(service_.get_io_service(),
-                               tcp::endpoint(tcp::v4(), TEST_PORT));
-        acceptor.async_accept(socket,
-            boost::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, _1));
-
-        // Post the TCP fetch object to send the query and receive the response.
-        service_.get_io_service().post(tcp_fetch_);
-
-        // ... and execute all the callbacks.  This exits when the fetch
-        // completes.
-        service_.run();
-        EXPECT_TRUE(run_);  // Make sure the callback did execute
-
-        // Tidy up
-        socket.close();
-    }
-
-    /// Perform a send/receive test over UDP
-    ///
-    /// \param bad_qid If true, do the test where the QID is mangled
-    ///                in the response
-    /// \param second_send If true, do the test where the QID is
-    ///                    mangled in the response, but a second
-    ///                    (correct) packet is used
-    void udpSendReturnTest(bool bad_qid, bool second_send) {
-        protocol_ = IOFetch::UDP;
-
-        // Set up the server.
-        udp::socket socket(service_.get_io_service(), udp::v4());
-        socket.set_option(socket_base::reuse_address(true));
-        socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
-        return_data_ = "Message returned to the client";
-
-        udp::endpoint remote;
-        socket.async_receive_from(asio::buffer(receive_buffer_, sizeof(receive_buffer_)),
-            remote,
-            boost::bind(&IOFetchTest::udpReceiveHandler, this, &remote, &socket,
-                        _1, _2, bad_qid, second_send));
-        service_.get_io_service().post(udp_fetch_);
-        if (debug_) {
-            cout << "udpSendReceive: async_receive_from posted, waiting for callback" <<
-                    endl;
-        }
-        service_.run();
-
-        socket.close();
-
-        EXPECT_TRUE(run_);;
-    }
-};
-
-// Check the protocol
-TEST_F(IOFetchTest, Protocol) {
-    EXPECT_EQ(IOFetch::UDP, udp_fetch_.getProtocol());
-    EXPECT_EQ(IOFetch::TCP, tcp_fetch_.getProtocol());
-}
-
-// UDP Stop test - see IOFetchTest::stopTest() header.
-TEST_F(IOFetchTest, UdpStop) {
-    stopTest(IOFetch::UDP, udp_fetch_);
-}
-
-// UDP premature stop test - see IOFetchTest::prematureStopTest() header.
-TEST_F(IOFetchTest, UdpPrematureStop) {
-    prematureStopTest(IOFetch::UDP, udp_fetch_);
-}
-
-// UDP premature stop test - see IOFetchTest::timeoutTest() header.
-TEST_F(IOFetchTest, UdpTimeout) {
-    timeoutTest(IOFetch::UDP, udp_fetch_);
-}
-
-// UDP SendReceive test.  Set up a UDP server then ports a UDP fetch object.
-// This will send question_ to the server and receive the answer back from it.
-TEST_F(IOFetchTest, UdpSendReceive) {
-    expected_ = IOFetch::SUCCESS;
-
-    udpSendReturnTest(false, false);
-
-    EXPECT_TRUE(run_);;
-}
-
-TEST_F(IOFetchTest, UdpSendReceiveBadQid) {
-    expected_ = IOFetch::TIME_OUT;
-
-    udpSendReturnTest(true, false);
-
-    EXPECT_TRUE(run_);;
-}
-
-TEST_F(IOFetchTest, UdpSendReceiveBadQidResend) {
-    expected_ = IOFetch::SUCCESS;
-
-    udpSendReturnTest(true, true);
-
-    EXPECT_TRUE(run_);;
-}
-
-// Do the same tests for TCP transport
-
-TEST_F(IOFetchTest, TcpStop) {
-    stopTest(IOFetch::TCP, tcp_fetch_);
-}
-
-TEST_F(IOFetchTest, TcpPrematureStop) {
-    prematureStopTest(IOFetch::TCP, tcp_fetch_);
-}
-
-TEST_F(IOFetchTest, TcpTimeout) {
-    timeoutTest(IOFetch::TCP, tcp_fetch_);
-}
-
-// Test with values at or near 2, then at or near the chunk size (16 and 32
-// bytes, the sizes of the first two packets) then up to 65535.  These are done
-// in separate tests because in practice a new IOFetch is created for each
-// query/response exchange and we don't want to confuse matters in the test
-// by running the test with an IOFetch that has already done one exchange.
-//
-// Don't do 0 or 1; the server would not accept the packet
-// (since the length is too short to check the qid)
-TEST_F(IOFetchTest, TcpSendReceive2) {
-    tcpSendReturnTest(test_data_.substr(0, 2));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive3) {
-    tcpSendReturnTest(test_data_.substr(0, 3));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive15) {
-    tcpSendReturnTest(test_data_.substr(0, 15));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive16) {
-    tcpSendReturnTest(test_data_.substr(0, 16));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive17) {
-    tcpSendReturnTest(test_data_.substr(0, 17));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive31) {
-    tcpSendReturnTest(test_data_.substr(0, 31));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive32) {
-    tcpSendReturnTest(test_data_.substr(0, 32));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive33) {
-    tcpSendReturnTest(test_data_.substr(0, 33));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive4096) {
-    tcpSendReturnTest(test_data_.substr(0, 4096));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive8192) {
-    tcpSendReturnTest(test_data_.substr(0, 8192));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive16384) {
-    tcpSendReturnTest(test_data_.substr(0, 16384));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive32768) {
-    tcpSendReturnTest(test_data_.substr(0, 32768));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive65535) {
-    tcpSendReturnTest(test_data_.substr(0, 65535));
-}
-
-TEST_F(IOFetchTest, TcpSendReceive2ShortSend) {
-    tcpSendReturnTest(test_data_.substr(0, 2), true);
-}
-
-TEST_F(IOFetchTest, TcpSendReceive15ShortSend) {
-    tcpSendReturnTest(test_data_.substr(0, 15), true);
-}
-
-TEST_F(IOFetchTest, TcpSendReceive8192ShortSend) {
-    tcpSendReturnTest(test_data_.substr(0, 8192), true);
-}
-
-
-} // namespace asiolink
diff --git a/src/lib/asiolink/tests/io_socket_unittest.cc b/src/lib/asiolink/tests/io_socket_unittest.cc
index 6538550..15afc17 100644
--- a/src/lib/asiolink/tests/io_socket_unittest.cc
+++ b/src/lib/asiolink/tests/io_socket_unittest.cc
@@ -20,7 +20,7 @@
 #include <asio.hpp>
 #include <asiolink/io_socket.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 
 TEST(IOSocketTest, dummySockets) {
     EXPECT_EQ(IPPROTO_UDP, IOSocket::getDummyUDPSocket().getProtocol());
diff --git a/src/lib/asiolink/tests/qid_gen_unittest.cc b/src/lib/asiolink/tests/qid_gen_unittest.cc
index 3ad8a03..346e6f4 100644
--- a/src/lib/asiolink/tests/qid_gen_unittest.cc
+++ b/src/lib/asiolink/tests/qid_gen_unittest.cc
@@ -39,8 +39,8 @@
 
 // Check that getInstance returns a singleton
 TEST(QidGenerator, singleton) {
-    asiolink::QidGenerator& g1 = asiolink::QidGenerator::getInstance();
-    asiolink::QidGenerator& g2 = asiolink::QidGenerator::getInstance();
+    isc::asiolink::QidGenerator& g1 = isc::asiolink::QidGenerator::getInstance();
+    isc::asiolink::QidGenerator& g2 = isc::asiolink::QidGenerator::getInstance();
 
     EXPECT_TRUE(&g1 == &g2);
 }
@@ -51,7 +51,7 @@ TEST(QidGenerator, generate) {
     // test (http://xkcd.com/221/), and check if three consecutive
     // generates are not all the same.
     isc::dns::qid_t one, two, three;
-    asiolink::QidGenerator& gen = asiolink::QidGenerator::getInstance();
+    isc::asiolink::QidGenerator& gen = isc::asiolink::QidGenerator::getInstance();
     one = gen.generateQid();
     two = gen.generateQid();
     three = gen.generateQid();
diff --git a/src/lib/asiolink/tests/tcp_endpoint_unittest.cc b/src/lib/asiolink/tests/tcp_endpoint_unittest.cc
index 3787e1c..6988082 100644
--- a/src/lib/asiolink/tests/tcp_endpoint_unittest.cc
+++ b/src/lib/asiolink/tests/tcp_endpoint_unittest.cc
@@ -22,7 +22,7 @@
 #include <asiolink/io_address.h>
 #include <asiolink/tcp_endpoint.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 using namespace std;
 
 // This test checks that the endpoint can manage its own internal
diff --git a/src/lib/asiolink/tests/tcp_socket_unittest.cc b/src/lib/asiolink/tests/tcp_socket_unittest.cc
index f0a45ee..e2d2365 100644
--- a/src/lib/asiolink/tests/tcp_socket_unittest.cc
+++ b/src/lib/asiolink/tests/tcp_socket_unittest.cc
@@ -46,7 +46,7 @@
 
 using namespace asio;
 using namespace asio::ip;
-using namespace asiolink;
+using namespace isc::asiolink;
 using namespace isc::dns;
 using namespace std;
 
diff --git a/src/lib/asiolink/tests/udp_endpoint_unittest.cc b/src/lib/asiolink/tests/udp_endpoint_unittest.cc
index 18135ec..03de6b8 100644
--- a/src/lib/asiolink/tests/udp_endpoint_unittest.cc
+++ b/src/lib/asiolink/tests/udp_endpoint_unittest.cc
@@ -22,7 +22,7 @@
 #include <asiolink/io_address.h>
 #include <asiolink/udp_endpoint.h>
 
-using namespace asiolink;
+using namespace isc::asiolink;
 using namespace std;
 
 // This test checks that the endpoint can manage its own internal
diff --git a/src/lib/asiolink/tests/udp_socket_unittest.cc b/src/lib/asiolink/tests/udp_socket_unittest.cc
index 8563d22..a98ed30 100644
--- a/src/lib/asiolink/tests/udp_socket_unittest.cc
+++ b/src/lib/asiolink/tests/udp_socket_unittest.cc
@@ -45,7 +45,7 @@
 #include <asiolink/udp_socket.h>
 
 using namespace asio;
-using namespace asiolink;
+using namespace isc::asiolink;
 using namespace isc::dns;
 using namespace std;
 
diff --git a/src/lib/asiolink/udp_endpoint.h b/src/lib/asiolink/udp_endpoint.h
index 99dc27f..5c8a1fe 100644
--- a/src/lib/asiolink/udp_endpoint.h
+++ b/src/lib/asiolink/udp_endpoint.h
@@ -21,6 +21,7 @@
 
 #include <asiolink/io_endpoint.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c UDPEndpoint class is a concrete derived class of
@@ -109,5 +110,6 @@ private:
     asio::ip::udp::endpoint& asio_endpoint_;
 };
 
-}      // namespace asiolink
+} // namespace asiolink
+} // namespace isc
 #endif // __UDP_ENDPOINT_H
diff --git a/src/lib/asiolink/udp_socket.h b/src/lib/asiolink/udp_socket.h
index 35fc7b1..d26d04c 100644
--- a/src/lib/asiolink/udp_socket.h
+++ b/src/lib/asiolink/udp_socket.h
@@ -33,6 +33,7 @@
 #include <asiolink/io_service.h>
 #include <asiolink/udp_endpoint.h>
 
+namespace isc {
 namespace asiolink {
 
 /// \brief The \c UDPSocket class is a concrete derived class of \c IOAsioSocket
@@ -318,5 +319,6 @@ UDPSocket<C>::close() {
 }
 
 } // namespace asiolink
+} // namespace isc
 
 #endif // __UDP_SOCKET_H




More information about the bind10-changes mailing list