[svn] commit: r3398 - in /branches/vorner-recursor-timeouts/src/lib/asiolink: asiolink.cc internal/udpdns.h tests/Makefile.am tests/udpdns_unittest.cc udpdns.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 29 13:01:35 UTC 2010


Author: vorner
Date: Fri Oct 29 13:01:34 2010
New Revision: 3398

Log:
Some tests for the UDPQuery

It does not link, unresolved UDPQuery.stop.

Added:
    branches/vorner-recursor-timeouts/src/lib/asiolink/tests/udpdns_unittest.cc
Modified:
    branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc
    branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h
    branches/vorner-recursor-timeouts/src/lib/asiolink/tests/Makefile.am
    branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc

Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/asiolink.cc Fri Oct 29 13:01:34 2010
@@ -231,10 +231,17 @@
 
 // This is just temporary so the interface change does not propagate too far
 struct ServerNotify : public UDPQuery::Callback {
-    DNSServer *server;
-    virtual void operator()(UDPQuery::Result result) {
-        server->resume(result == UDPQuery::SUCCESS);
-    }
+        ServerNotify(DNSServer *server) :
+            server_(server)
+        { }
+        virtual void operator()(UDPQuery::Result result) {
+            server_->resume(result == UDPQuery::SUCCESS);
+            delete this;
+        }
+    private:
+        // FIXME This is said it does problems when it is shared pointer, as
+        // it is destroyed too soon. But who deletes it now?
+        DNSServer *server_;
 };
 
 }
@@ -249,11 +256,8 @@
     // UDP and then fall back to TCP on failure, but for the moment
     // we're only going to handle UDP.
     asio::io_service& io = dns_service_.get_io_service();
-    boost::shared_ptr<ServerNotify> callback(new ServerNotify);
-    // FIXME This is said it does problems when it is shared pointer, as
-    // it is destroyed too soon. But who deletes it now?
-    callback->server = server->clone();
-    UDPQuery q(io, question, ns_addr_, port_, buffer, callback);
+    UDPQuery q(io, question, ns_addr_, port_, buffer,
+        new ServerNotify(server->clone()));
     io.post(q);
 }
 

Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/internal/udpdns.h Fri Oct 29 13:01:34 2010
@@ -198,13 +198,21 @@
             /// This will be called when the UDPQuery is completed
             virtual void operator()(Result result) = 0;
     };
+    /**
+     * \short Constructor.
+     *
+     * It creates the query.
+     * @param callback will be called when we terminate. It is your task to
+     *     delete it if allocated on heap.
+     * @param timeout in ms.
+     */
     explicit UDPQuery(asio::io_service& io_service,
                       const isc::dns::Question& q,
                       const IOAddress& addr, uint16_t port,
                       isc::dns::OutputBufferPtr buffer,
-                      boost::shared_ptr<Callback> callback, int timeout = -1);
+                      Callback *callback, int timeout = -1);
     void operator()(asio::error_code ec = asio::error_code(),
-                    size_t length = 0); 
+                    size_t length = 0);
     /// Terminate the query.
     void stop(Result reason = STOPPED);
 private:
@@ -239,7 +247,7 @@
     boost::shared_array<char> data_;
 
     // This will be called when we are done.
-    boost::shared_ptr<Callback> callback_;
+    Callback *callback_;
 };
 }
 

Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/tests/Makefile.am
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/tests/Makefile.am (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/tests/Makefile.am Fri Oct 29 13:01:34 2010
@@ -17,6 +17,7 @@
 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 += asiolink_unittest.cc
+run_unittests_SOURCES += udpdns_unittest.cc
 run_unittests_SOURCES += run_unittests.cc
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)

Modified: branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc
==============================================================================
--- branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc (original)
+++ branches/vorner-recursor-timeouts/src/lib/asiolink/udpdns.cc Fri Oct 29 13:01:34 2010
@@ -176,8 +176,7 @@
 /// The constructor
 UDPQuery::UDPQuery(io_service& io_service,
                    const Question& q, const IOAddress& addr, uint16_t port,
-                   OutputBufferPtr buffer,
-                   boost::shared_ptr<Callback> callback, int timeout) :
+                   OutputBufferPtr buffer, Callback *callback, int timeout) :
     question_(q), buffer_(buffer), callback_(callback)
 {
     udp proto = (addr.getFamily() == AF_INET) ? udp::v4() : udp::v6();




More information about the bind10-changes mailing list