Browse Source

[trac554] Changed UDPQuery to IOFetch everywhere

Scott Mann 14 years ago
parent
commit
bc3d1d70a2

+ 1 - 1
src/lib/asiolink/README

@@ -33,7 +33,7 @@ This is intended to simplify development a bit, since it allows the
 routines to be written in a straightfowrard step-step-step fashion rather
 routines to be written in a straightfowrard step-step-step fashion rather
 than as a complex chain of separate handler functions.
 than as a complex chain of separate handler functions.
 
 
-Coroutine objects (i.e., UDPServer, TCPServer and UDPQuery) are objects
+Coroutine objects (i.e., UDPServer, TCPServer and IOFetch) are objects
 with reenterable operator() members.  When an instance of one of these
 with reenterable operator() members.  When an instance of one of these
 classes is called as a function, it resumes at the position where it left
 classes is called as a function, it resumes at the position where it left
 off.  Thus, a UDPServer can issue an asynchronous I/O call and specify
 off.  Thus, a UDPServer can issue an asynchronous I/O call and specify

+ 6 - 6
src/lib/asiolink/asiolink.cc

@@ -339,7 +339,7 @@ namespace {
  *
  *
  * Used by RecursiveQuery::sendQuery.
  * Used by RecursiveQuery::sendQuery.
  */
  */
-class RunningQuery : public UDPQuery::Callback {
+class RunningQuery : public IOFetch::Callback {
 private:
 private:
     // The io service to handle async calls
     // The io service to handle async calls
     asio::io_service& io_;
     asio::io_service& io_;
@@ -399,7 +399,7 @@ private:
             int serverIndex = rand() % uc;
             int serverIndex = rand() % uc;
             dlog("Sending upstream query (" + question_.toText() +
             dlog("Sending upstream query (" + question_.toText() +
                 ") to " + upstream_->at(serverIndex).first);
                 ") to " + upstream_->at(serverIndex).first);
-            UDPQuery query(io_, question_,
+            IOFetch query(io_, question_,
                 upstream_->at(serverIndex).first,
                 upstream_->at(serverIndex).first,
                 upstream_->at(serverIndex).second, buffer_, this,
                 upstream_->at(serverIndex).second, buffer_, this,
                 query_timeout_);
                 query_timeout_);
@@ -409,7 +409,7 @@ private:
             int serverIndex = rand() % zs;
             int serverIndex = rand() % zs;
             dlog("Sending query to zone server (" + question_.toText() +
             dlog("Sending query to zone server (" + question_.toText() +
                 ") to " + zone_servers_.at(serverIndex).first);
                 ") to " + zone_servers_.at(serverIndex).first);
-            UDPQuery query(io_, question_,
+            IOFetch query(io_, question_,
                 zone_servers_.at(serverIndex).first,
                 zone_servers_.at(serverIndex).first,
                 zone_servers_.at(serverIndex).second, buffer_, this,
                 zone_servers_.at(serverIndex).second, buffer_, this,
                 query_timeout_);
                 query_timeout_);
@@ -572,10 +572,10 @@ public:
     }
     }
 
 
     // This function is used as callback from DNSQuery.
     // This function is used as callback from DNSQuery.
-    virtual void operator()(UDPQuery::Result result) {
+    virtual void operator()(IOFetch::Result result) {
         // XXX is this the place for TCP retry?
         // XXX is this the place for TCP retry?
         --queries_out_;
         --queries_out_;
-        if (!done_ && result != UDPQuery::TIME_OUT) {
+        if (!done_ && result != IOFetch::TIME_OUT) {
             // we got an answer
             // we got an answer
             Message incoming(Message::PARSE);
             Message incoming(Message::PARSE);
             InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
             InputBuffer ibuf(buffer_->getData(), buffer_->getLength());
@@ -590,7 +590,7 @@ public:
             }
             }
             
             
             if (done_) {
             if (done_) {
-                stop(result == UDPQuery::SUCCESS);
+                stop(result == IOFetch::SUCCESS);
             }
             }
         } else if (!done_ && retries_--) {
         } else if (!done_ && retries_--) {
             // We timed out, but we have some retries, so send again
             // We timed out, but we have some retries, so send again

+ 8 - 8
src/lib/asiolink/internal/iofetch.h

@@ -12,8 +12,8 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 // PERFORMANCE OF THIS SOFTWARE.
 
 
-#ifndef __IOQUERY_H
-#define __IOQUERY_H 1
+#ifndef __IOFETCH_H
+#define __IOFETCH_H 1
 
 
 #include <config.h>
 #include <config.h>
 
 
@@ -36,9 +36,9 @@ namespace asiolink {
 //
 //
 // Asynchronous UDP coroutine for upstream queries
 // Asynchronous UDP coroutine for upstream queries
 //
 //
-class UDPQuery : public coroutine {
+class IOFetch : public coroutine {
 public:
 public:
-    // TODO Maybe this should be more generic than just for UDPQuery?
+    // TODO Maybe this should be more generic than just for IOFetch?
     ///
     ///
     /// \brief Result of the query
     /// \brief Result of the query
     ///
     ///
@@ -50,12 +50,12 @@ public:
         TIME_OUT,
         TIME_OUT,
         STOPPED
         STOPPED
     };
     };
-    /// Abstract callback for the UDPQuery.
+    /// Abstract callback for the IOFetch.
     class Callback {
     class Callback {
     public:
     public:
         virtual ~Callback() {}
         virtual ~Callback() {}
 
 
-        /// This will be called when the UDPQuery is completed
+        /// This will be called when the IOFetch is completed
         virtual void operator()(Result result) = 0;
         virtual void operator()(Result result) = 0;
     };
     };
     ///
     ///
@@ -66,7 +66,7 @@ public:
     ///        delete it if allocated on heap.
     ///        delete it if allocated on heap.
     ///@param timeout in ms.
     ///@param timeout in ms.
     ///
     ///
-    explicit UDPQuery(asio::io_service& io_service,
+    explicit IOFetch(asio::io_service& io_service,
                       const isc::dns::Question& q,
                       const isc::dns::Question& q,
                       const IOAddress& addr, uint16_t port,
                       const IOAddress& addr, uint16_t port,
                       isc::dns::OutputBufferPtr buffer,
                       isc::dns::OutputBufferPtr buffer,
@@ -93,7 +93,7 @@ private:
 }
 }
 
 
 
 
-#endif // __IOQUERY_H
+#endif // __IOFETCH_H
 
 
 // Local Variables: 
 // Local Variables: 
 // mode: c++
 // mode: c++

+ 19 - 19
src/lib/asiolink/internal/tests/udpdns_unittest.cc

@@ -33,25 +33,25 @@ const uint16_t TEST_PORT(5301);
 // FIXME Shouldn't we send something that is real message?
 // FIXME Shouldn't we send something that is real message?
 const char TEST_DATA[] = "TEST DATA";
 const char TEST_DATA[] = "TEST DATA";
 
 
-// Test fixture for the asiolink::UDPQuery.
-class UDPQueryTest : public ::testing::Test,
-    public asiolink::UDPQuery::Callback
+// Test fixture for the asiolink::IOFetch.
+class IOFetchTest : public ::testing::Test,
+    public asiolink::IOFetch::Callback
 {
 {
     public:
     public:
         // Expected result of the callback
         // Expected result of the callback
-        asiolink::UDPQuery::Result expected_;
+        asiolink::IOFetch::Result expected_;
         // Did the callback run already?
         // Did the callback run already?
         bool run_;
         bool run_;
         // We use an io_service to run the query
         // We use an io_service to run the query
         io_service service_;
         io_service service_;
         // Something to ask
         // Something to ask
         Question question_;
         Question question_;
-        // Buffer where the UDPQuery will store response
+        // Buffer where the IOFetch will store response
         OutputBufferPtr buffer_;
         OutputBufferPtr buffer_;
         // The query we are testing
         // The query we are testing
-        asiolink::UDPQuery query_;
+        asiolink::IOFetch query_;
 
 
-        UDPQueryTest() :
+        IOFetchTest() :
             run_(false),
             run_(false),
             question_(Name("example.net"), RRClass::IN(), RRType::A()),
             question_(Name("example.net"), RRClass::IN(), RRType::A()),
             buffer_(new OutputBuffer(512)),
             buffer_(new OutputBuffer(512)),
@@ -60,7 +60,7 @@ class UDPQueryTest : public ::testing::Test,
         { }
         { }
 
 
         // This is the callback's (), so it can be called.
         // This is the callback's (), so it can be called.
-        void operator()(asiolink::UDPQuery::Result result) {
+        void operator()(asiolink::IOFetch::Result result) {
             // We check the query returns the correct result
             // We check the query returns the correct result
             EXPECT_EQ(expected_, result);
             EXPECT_EQ(expected_, result);
             // Check it is called only once
             // Check it is called only once
@@ -84,14 +84,14 @@ class UDPQueryTest : public ::testing::Test,
  * That is why stop() is posted to the service_ as well instead
  * That is why stop() is posted to the service_ as well instead
  * of calling it.
  * of calling it.
  */
  */
-TEST_F(UDPQueryTest, stop) {
-    expected_ = asiolink::UDPQuery::STOPPED;
+TEST_F(IOFetchTest, stop) {
+    expected_ = asiolink::IOFetch::STOPPED;
     // Post the query
     // Post the query
     service_.post(query_);
     service_.post(query_);
     // Post query_.stop() (yes, the boost::bind thing is just
     // Post query_.stop() (yes, the boost::bind thing is just
     // query_.stop()).
     // query_.stop()).
-    service_.post(boost::bind(&asiolink::UDPQuery::stop, query_,
-        asiolink::UDPQuery::STOPPED));
+    service_.post(boost::bind(&asiolink::IOFetch::stop, query_,
+        asiolink::IOFetch::STOPPED));
     // Run both of them
     // Run both of them
     service_.run();
     service_.run();
     EXPECT_TRUE(run_);
     EXPECT_TRUE(run_);
@@ -102,8 +102,8 @@ TEST_F(UDPQueryTest, stop) {
  * before it gets executed, it acts sanely as well (eg. has the
  * before it gets executed, it acts sanely as well (eg. has the
  * same result as running stop() after - calls the callback).
  * same result as running stop() after - calls the callback).
  */
  */
-TEST_F(UDPQueryTest, prematureStop) {
-    expected_ = asiolink::UDPQuery::STOPPED;
+TEST_F(IOFetchTest, prematureStop) {
+    expected_ = asiolink::IOFetch::STOPPED;
     // Stop before it is started
     // Stop before it is started
     query_.stop();
     query_.stop();
     service_.post(query_);
     service_.post(query_);
@@ -114,8 +114,8 @@ TEST_F(UDPQueryTest, prematureStop) {
 /*
 /*
  * Test that it will timeout when no answer will arrive.
  * Test that it will timeout when no answer will arrive.
  */
  */
-TEST_F(UDPQueryTest, timeout) {
-    expected_ = asiolink::UDPQuery::TIME_OUT;
+TEST_F(IOFetchTest, timeout) {
+    expected_ = asiolink::IOFetch::TIME_OUT;
     service_.post(query_);
     service_.post(query_);
     service_.run();
     service_.run();
     EXPECT_TRUE(run_);
     EXPECT_TRUE(run_);
@@ -127,15 +127,15 @@ TEST_F(UDPQueryTest, timeout) {
  *
  *
  * This is done through a real socket on loopback address.
  * This is done through a real socket on loopback address.
  */
  */
-TEST_F(UDPQueryTest, receive) {
-    expected_ = asiolink::UDPQuery::SUCCESS;
+TEST_F(IOFetchTest, receive) {
+    expected_ = asiolink::IOFetch::SUCCESS;
     udp::socket socket(service_, udp::v4());
     udp::socket socket(service_, udp::v4());
     socket.set_option(socket_base::reuse_address(true));
     socket.set_option(socket_base::reuse_address(true));
     socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
     socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
     char inbuff[512];
     char inbuff[512];
     udp::endpoint remote;
     udp::endpoint remote;
     socket.async_receive_from(asio::buffer(inbuff, 512), remote, boost::bind(
     socket.async_receive_from(asio::buffer(inbuff, 512), remote, boost::bind(
-        &UDPQueryTest::respond, this, &remote, &socket));
+        &IOFetchTest::respond, this, &remote, &socket));
     service_.post(query_);
     service_.post(query_);
     service_.run();
     service_.run();
     EXPECT_TRUE(run_);
     EXPECT_TRUE(run_);

+ 7 - 7
src/lib/asiolink/iofetch.cc

@@ -50,8 +50,8 @@ using namespace isc::dns;
 
 
 namespace asiolink {
 namespace asiolink {
 
 
-// Private UDPQuery data (see internal/udpdns.h for reasons)
-struct UDPQuery::PrivateData {
+// Private IOFetch data (see internal/udpdns.h for reasons)
+struct IOFetch::PrivateData {
     // UDP Socket we send query to and expect reply from there
     // UDP Socket we send query to and expect reply from there
     udp::socket socket;
     udp::socket socket;
     // Where was the query sent
     // Where was the query sent
@@ -91,10 +91,10 @@ struct UDPQuery::PrivateData {
     { }
     { }
 };
 };
 
 
-/// The following functions implement the \c UDPQuery class.
+/// The following functions implement the \c IOFetch class.
 ///
 ///
 /// The constructor
 /// The constructor
-UDPQuery::UDPQuery(io_service& io_service,
+IOFetch::IOFetch(io_service& io_service,
                    const Question& q, const IOAddress& addr, uint16_t port,
                    const Question& q, const IOAddress& addr, uint16_t port,
                    OutputBufferPtr buffer, Callback *callback, int timeout) :
                    OutputBufferPtr buffer, Callback *callback, int timeout) :
     data_(new PrivateData(io_service,
     data_(new PrivateData(io_service,
@@ -108,7 +108,7 @@ UDPQuery::UDPQuery(io_service& io_service,
 /// The function operator is implemented with the "stackless coroutine"
 /// The function operator is implemented with the "stackless coroutine"
 /// pattern; see internal/coroutine.h for details.
 /// pattern; see internal/coroutine.h for details.
 void
 void
-UDPQuery::operator()(error_code ec, size_t length) {
+IOFetch::operator()(error_code ec, size_t length) {
     if (ec || data_->stopped) {
     if (ec || data_->stopped) {
         return;
         return;
     }
     }
@@ -138,7 +138,7 @@ UDPQuery::operator()(error_code ec, size_t length) {
         if (data_->timeout != -1) {
         if (data_->timeout != -1) {
             data_->timer.expires_from_now(boost::posix_time::milliseconds(
             data_->timer.expires_from_now(boost::posix_time::milliseconds(
                 data_->timeout));
                 data_->timeout));
-            data_->timer.async_wait(boost::bind(&UDPQuery::stop, *this,
+            data_->timer.async_wait(boost::bind(&IOFetch::stop, *this,
                 TIME_OUT));
                 TIME_OUT));
         }
         }
 
 
@@ -171,7 +171,7 @@ UDPQuery::operator()(error_code ec, size_t length) {
 }
 }
 
 
 void
 void
-UDPQuery::stop(Result result) {
+IOFetch::stop(Result result) {
     if (!data_->stopped) {
     if (!data_->stopped) {
         switch (result) {
         switch (result) {
             case TIME_OUT:
             case TIME_OUT: