BIND 10 trac499, updated. 5017cbe7d18c752b80e8e8289b9ab0315f5915d0 [trac499] Add ability to determing protocol used by IOFetch
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Mar 1 12:22:15 UTC 2011
The branch, trac499 has been updated
via 5017cbe7d18c752b80e8e8289b9ab0315f5915d0 (commit)
from 77027490d53b644e157fce2df59c5dbd496d1e1a (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 5017cbe7d18c752b80e8e8289b9ab0315f5915d0
Author: Stephen Morris <stephen at isc.org>
Date: Tue Mar 1 12:21:39 2011 +0000
[trac499] Add ability to determing protocol used by IOFetch
-----------------------------------------------------------------------
Summary of changes:
src/lib/asiolink/io_fetch.cc | 23 ++++++++++++++++-------
src/lib/asiolink/io_fetch.h | 24 +++++++++++-------------
src/lib/asiolink/tests/io_fetch_unittest.cc | 11 ++++++++---
src/lib/asiolink/tests/run_unittests.cc | 6 ++++--
4 files changed, 39 insertions(+), 25 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/asiolink/io_fetch.cc b/src/lib/asiolink/io_fetch.cc
index 82e1907..717d3d9 100644
--- a/src/lib/asiolink/io_fetch.cc
+++ b/src/lib/asiolink/io_fetch.cc
@@ -52,7 +52,7 @@ namespace asiolink {
/// Use the ASIO logger
-isc::log::Logger logger("asio");
+isc::log::Logger logger("asiolink");
/// \brief IOFetch Data
///
@@ -75,9 +75,10 @@ struct IOFetchData {
isc::dns::OutputBufferPtr received; ///< Received data put here
boost::shared_array<char> staging; ///< Temporary array for received data
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
bool stopped; ///< Have we stopped running?
- asio::deadline_timer timer; ///< Timer to measure timeouts
int timeout; ///< Timeout in ms
// In case we need to log an error, the origin of the last asynchronous
@@ -91,7 +92,7 @@ struct IOFetchData {
///
/// Just fills in the data members of the IOFetchData structure
///
- /// \param protocol Either IOFetch::TCP or IOFetch::UDP.
+ /// \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.
@@ -105,18 +106,18 @@ struct IOFetchData {
/// \param wait Timeout for the fetch (in ms).
///
/// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
- IOFetchData(IOFetch::Protocol protocol, IOService& service,
+ 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((protocol == IOFetch::UDP) ?
+ socket((proto == IOFetch::UDP) ?
static_cast<IOAsioSocket<IOFetch>*>(
new UDPSocket<IOFetch>(service)) :
static_cast<IOAsioSocket<IOFetch>*>(
new TCPSocket<IOFetch>(service))
),
- remote((protocol == IOFetch::UDP) ?
+ remote((proto == IOFetch::UDP) ?
static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
static_cast<IOEndpoint*>(new TCPEndpoint(address, port))
),
@@ -125,9 +126,10 @@ struct IOFetchData {
received(buff),
staging(new char[IOFetch::MIN_LENGTH]),
callback(cb),
+ timer(service.get_io_service()),
+ protocol(proto),
cumulative(0),
stopped(false),
- timer(service.get_io_service()),
timeout(wait),
origin(ASIO_UNKORIGIN)
{}
@@ -144,6 +146,13 @@ IOFetch::IOFetch(Protocol protocol, IOService& service,
{
}
+// 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.
diff --git a/src/lib/asiolink/io_fetch.h b/src/lib/asiolink/io_fetch.h
index 479c54c..ce39f0a 100644
--- a/src/lib/asiolink/io_fetch.h
+++ b/src/lib/asiolink/io_fetch.h
@@ -17,15 +17,14 @@
#include <config.h>
-
#include <boost/shared_array.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
-#include <asio/error_code.hpp>
-
#include <coroutine.h>
+#include <asio/error_code.hpp>
+
#include <dns/buffer.h>
#include <dns/question.h>
@@ -138,6 +137,11 @@ public:
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
@@ -145,16 +149,7 @@ public:
///
/// \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, size_t length);
-
- void operator()(asio::error_code ec) {
- operator()(ec, 0);
- }
-
- void operator()() {
- asio::error_code ec;
- operator()(ec);
- }
+ void operator()(asio::error_code ec = asio::error_code(), size_t length = 0);
/// \brief Terminate query
///
@@ -172,6 +167,9 @@ private:
/// \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
};
diff --git a/src/lib/asiolink/tests/io_fetch_unittest.cc b/src/lib/asiolink/tests/io_fetch_unittest.cc
index d743df2..c196181 100644
--- a/src/lib/asiolink/tests/io_fetch_unittest.cc
+++ b/src/lib/asiolink/tests/io_fetch_unittest.cc
@@ -338,18 +338,23 @@ public:
}
};
+// 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.
+// UDP Stop test - see IOFetchTest::stopTest() header.
TEST_F(IOFetchTest, UdpStop) {
stopTest(IOFetch::UDP, udp_fetch_);
}
-/// UDP premature stop test - see IOFetchTest::prematureStopTest() header.
+// 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.
+// UDP premature stop test - see IOFetchTest::timeoutTest() header.
TEST_F(IOFetchTest, UdpTimeout) {
timeoutTest(IOFetch::UDP, udp_fetch_);
}
diff --git a/src/lib/asiolink/tests/run_unittests.cc b/src/lib/asiolink/tests/run_unittests.cc
index b481784..c285f9e 100644
--- a/src/lib/asiolink/tests/run_unittests.cc
+++ b/src/lib/asiolink/tests/run_unittests.cc
@@ -14,13 +14,15 @@
#include <gtest/gtest.h>
+#include <log/root_logger_name.h>
#include <dns/tests/unittest_util.h>
int
main(int argc, char* argv[])
{
- ::testing::InitGoogleTest(&argc, argv);
- isc::UnitTestUtil::addDataPath(TEST_DATA_DIR);
+ ::testing::InitGoogleTest(&argc, argv); // Initialize Google test
+ isc::log::setRootLoggerName("unittest"); // Set a root logger name
+ isc::UnitTestUtil::addDataPath(TEST_DATA_DIR); // Add location of test data
return (RUN_ALL_TESTS());
}
More information about the bind10-changes
mailing list