BIND 10 trac1599, updated. ccc2fb769ced7cef416b55d9074591022b8a673b [1599] Comment some members
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 23 10:14:16 UTC 2012
The branch, trac1599 has been updated
via ccc2fb769ced7cef416b55d9074591022b8a673b (commit)
via 69360a12e78e7567f88dcd3079c9a56be534ea7d (commit)
from 6ec73d5de3e72a8d6adbb7e3bc353b68584b344f (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 ccc2fb769ced7cef416b55d9074591022b8a673b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Feb 23 11:13:50 2012 +0100
[1599] Comment some members
commit 69360a12e78e7567f88dcd3079c9a56be534ea7d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Feb 23 11:05:08 2012 +0100
[1599] Some more tests, to confirm exceptions
-----------------------------------------------------------------------
Summary of changes:
src/lib/asiodns/sync_udp_server.h | 26 ++++++++++++++-
src/lib/asiodns/tests/dns_server_unittest.cc | 47 ++++++++++++++++++++-----
2 files changed, 62 insertions(+), 11 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/asiodns/sync_udp_server.h b/src/lib/asiodns/sync_udp_server.h
index 5c1b72e..de9eb51 100644
--- a/src/lib/asiodns/sync_udp_server.h
+++ b/src/lib/asiodns/sync_udp_server.h
@@ -109,19 +109,43 @@ public:
isc_throw(Unexpected, "SyncUDPServer can't be cloned.");
}
private:
+ // Internal state & buffers. We don't use the PIMPL idiom, as this class
+ // isn't usually used directly anyway.
+
+ // Maximum size of incoming UDP packet
static const size_t MAX_LENGTH = 4096;
+ // Buffer for incoming data
uint8_t data_[MAX_LENGTH];
+ // The buffer to render the output to and send it.
+ // If it was OK to have just a buffer, not the wrapper class,
+ // we could reuse the data_
isc::util::OutputBufferPtr output_buffer_;
+ // Objects to hold the query message and the answer
isc::dns::MessagePtr query_, answer_;
+ // The socket used for the communication
std::auto_ptr<asio::ip::udp::socket> socket_;
+ // The event loop we use
asio::io_service& io_;
+ // Place the socket puts the sender of a packet when it is received
asio::ip::udp::endpoint sender_;
+ // Callbacks
const asiolink::SimpleCallback* checkin_callback_;
const DNSLookup* lookup_callback_;
const DNSAnswer* answer_callback_;
- bool resume_called_, done_, stopped_;
+ // Answers from the lookup callback (not sent directly, but signalled
+ // through resume()
+ bool resume_called_, done_;
+ // This turns true when the server stops. Allows for not sending the
+ // answer after we closed the socket.
+ bool stopped_;
+
+ // Auxiliary functions
+ // Schedule next read on the socket. Just a wrapper around
+ // socket_->async_read_from with the correct parameters.
void scheduleRead();
+ // Callback from the socket's read call (called when there's an error or
+ // when a new packet comes).
void handleRead(const asio::error_code& ec, const size_t length);
};
diff --git a/src/lib/asiodns/tests/dns_server_unittest.cc b/src/lib/asiodns/tests/dns_server_unittest.cc
index 18ec1bc..0064bba 100644
--- a/src/lib/asiodns/tests/dns_server_unittest.cc
+++ b/src/lib/asiodns/tests/dns_server_unittest.cc
@@ -113,15 +113,22 @@ class DummyChecker : public SimpleCallback, public ServerStopper {
// \brief no lookup logic at all,just provide a checkpoint to stop the server
class DummyLookup : public DNSLookup, public ServerStopper {
- public:
- void operator()(const IOMessage& io_message,
- isc::dns::MessagePtr message,
- isc::dns::MessagePtr answer_message,
- isc::util::OutputBufferPtr buffer,
- DNSServer* server) const {
- stopServer();
+public:
+ DummyLookup() :
+ allow_resume_(true)
+ { }
+ void operator()(const IOMessage& io_message,
+ isc::dns::MessagePtr message,
+ isc::dns::MessagePtr answer_message,
+ isc::util::OutputBufferPtr buffer,
+ DNSServer* server) const {
+ stopServer();
+ if (allow_resume_) {
server->resume(true);
}
+ }
+ // If you want it not to call resume, set this to false
+ bool allow_resume_;
};
// \brief copy the data received from user to the answer part
@@ -500,6 +507,12 @@ bool DNSServerTestBase<UDPServerClass>::io_service_is_time_out = false;
template<class UDPServerClass>
asio::io_service* DNSServerTestBase<UDPServerClass>::current_service(NULL);
+typedef ::testing::Types<AddrPortInit<SyncUDPServer>, FdInit<SyncUDPServer> >
+ SyncTypes;
+template<class Parent>
+class SyncServerTest : public Parent { };
+TYPED_TEST_CASE(SyncServerTest, SyncTypes);
+
// Test whether server stopped successfully after client get response
// client will send query and start to wait for response, once client
// get response, udp server will be stopped, the io service won't quit
@@ -628,10 +641,9 @@ TYPED_TEST(DNSServerTest, stopTCPServeMoreThanOnce) {
TYPED_TEST(DNSServerTestBase, invalidFamily) {
// We abuse DNSServerTestBase for this test, as we don't need the
// initialization.
- EXPECT_THROW(UDPServer(this->service, 0, AF_UNIX, this->checker_,
+ EXPECT_THROW(TypeParam(this->service, 0, AF_UNIX, this->checker_,
this->lookup_, this->answer_),
isc::InvalidParameter);
- // TODO The sync UDP server as well, please
EXPECT_THROW(TCPServer(this->service, 0, AF_UNIX, this->checker_,
this->lookup_, this->answer_),
isc::InvalidParameter);
@@ -663,9 +675,24 @@ TYPED_TEST(DNSServerTestBase, DISABLED_invalidUDPFD) {
not the others, maybe we could make it run this at least on epoll-based
systems).
*/
- EXPECT_THROW(UDPServer(this->service, -1, AF_INET, this->checker_,
+ EXPECT_THROW(TypeParam(this->service, -1, AF_INET, this->checker_,
this->lookup_, this->answer_),
isc::asiolink::IOError);
}
+// Check it rejects some of the unsupported operatirons
+TYPED_TEST(SyncServerTest, unsupportedOps) {
+ EXPECT_THROW(this->udp_server_->clone(), isc::Unexpected);
+ EXPECT_THROW(this->udp_server_->asyncLookup(), isc::Unexpected);
+}
+
+// Check it rejects forgotten resume (eg. insists that it is synchronous)
+TYPED_TEST(SyncServerTest, mustResume) {
+ this->lookup_->allow_resume_ = false;
+ ASSERT_THROW(this->testStopServerByStopper(this->udp_server_,
+ this->udp_client_,
+ this->lookup_),
+ isc::Unexpected);
+}
+
}
More information about the bind10-changes
mailing list