BIND 10 trac826, updated. 284dc18ec942163778072e8c26dfef96ae7a2a79 xfr (skipped)

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jun 28 13:56:23 UTC 2012


The branch, trac826 has been updated
       via  284dc18ec942163778072e8c26dfef96ae7a2a79 (commit)
      from  52346cbce7274e7a598be24b4f8a3eccf090e4f1 (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 284dc18ec942163778072e8c26dfef96ae7a2a79
Author: Francis Dupont <fdupont at isc.org>
Date:   Thu Jun 28 15:56:10 2012 +0200

    xfr (skipped)

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

Summary of changes:
 src/lib/xfr/Makefile.am                            |    2 +
 src/lib/{acl => xfr}/tests/.gitignore              |    0
 src/lib/xfr/tests/Makefile.am                      |   28 +++++++++++++
 .../tempdir.h.in => xfr/tests/client_test.cc}      |   26 +++++++-----
 src/lib/{acl => xfr}/tests/run_unittests.cc        |    1 -
 src/lib/xfr/xfrout_client.cc                       |   42 ++++++++++++--------
 6 files changed, 72 insertions(+), 27 deletions(-)
 copy src/lib/{acl => xfr}/tests/.gitignore (100%)
 create mode 100644 src/lib/xfr/tests/Makefile.am
 copy src/lib/{log/tests/tempdir.h.in => xfr/tests/client_test.cc} (61%)
 copy src/lib/{acl => xfr}/tests/run_unittests.cc (99%)

-----------------------------------------------------------------------
diff --git a/src/lib/xfr/Makefile.am b/src/lib/xfr/Makefile.am
index d714990..3d7f60f 100644
--- a/src/lib/xfr/Makefile.am
+++ b/src/lib/xfr/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = . tests
+
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
 AM_CPPFLAGS += $(BOOST_INCLUDES)
diff --git a/src/lib/xfr/tests/.gitignore b/src/lib/xfr/tests/.gitignore
new file mode 100644
index 0000000..d6d1ec8
--- /dev/null
+++ b/src/lib/xfr/tests/.gitignore
@@ -0,0 +1 @@
+/run_unittests
diff --git a/src/lib/xfr/tests/Makefile.am b/src/lib/xfr/tests/Makefile.am
new file mode 100644
index 0000000..e8f187f
--- /dev/null
+++ b/src/lib/xfr/tests/Makefile.am
@@ -0,0 +1,28 @@
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CXXFLAGS = $(B10_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+        $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = run_unittests.cc client_test.cc
+
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+
+run_unittests_LDADD = $(GTEST_LDADD)
+run_unittests_LDADD += $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
+run_unittests_LDADD += $(top_builddir)/src/lib/xfr/libxfr.la
+run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
+endif
+
+noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/xfr/tests/client_test.cc b/src/lib/xfr/tests/client_test.cc
new file mode 100644
index 0000000..6c9f4ad
--- /dev/null
+++ b/src/lib/xfr/tests/client_test.cc
@@ -0,0 +1,37 @@
+// 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 <gtest/gtest.h>
+
+#include <sys/un.h>
+#include <string>
+
+#include <xfr/xfrout_client.h>
+
+using namespace std;
+using namespace isc::xfr;
+
+namespace {
+
+TEST(ClientTest, connetFile) {
+    // File path is too long
+    struct sockaddr_un s;     // can't be const; some compiler complains
+    EXPECT_THROW(XfroutClient(string(sizeof(s.sun_path), 'x')).connect(),
+                 XfroutError);
+
+    // File doesn't exist (we assume the file "no_such_file" doesn't exist)
+    EXPECT_THROW(XfroutClient("no_such_file").connect(), XfroutError);
+}
+
+}
diff --git a/src/lib/xfr/tests/run_unittests.cc b/src/lib/xfr/tests/run_unittests.cc
new file mode 100644
index 0000000..650a251
--- /dev/null
+++ b/src/lib/xfr/tests/run_unittests.cc
@@ -0,0 +1,39 @@
+// 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>
+
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
+
+#include <gtest/gtest.h>
+#include <log/logger_support.h>
+#include <util/unittests/run_all.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+    isc::log::initLogger();
+
+#ifdef _WIN32
+    WSADATA wsaData;
+    WSAStartup(MAKEWORD(2,2), &wsaData);
+    int ret = isc::util::unittests::run_all();
+    WSACleanup();
+    return (ret);
+#else
+    return (isc::util::unittests::run_all());
+#endif
+}
diff --git a/src/lib/xfr/xfrout_client.cc b/src/lib/xfr/xfrout_client.cc
index 43262f4..9dae821 100644
--- a/src/lib/xfr/xfrout_client.cc
+++ b/src/lib/xfr/xfrout_client.cc
@@ -20,7 +20,6 @@
 #ifndef _WIN32
 #include <unistd.h>
 #endif
-#include <config.h>
 #include <asio.hpp>
 
 #include <util/io/fd_share.h>
@@ -61,23 +60,25 @@ XfroutClient::~XfroutClient() {
 
 void
 XfroutClient::connect() {
-    asio::error_code err;
+    try {
+        impl_->socket_.connect(stream_protocol::endpoint(impl_->file_path_));
 #ifndef _WIN32
-    stream_protocol::endpoint ep(impl_->file_path_);
+        stream_protocol::endpoint ep(impl_->file_path_);
 #else
-    asio::ip::address addr;
-    if (impl_->file_path_.find("v4_") == 0)
-        addr = asio::ip::address_v4::loopback();
-    else if (impl_->file_path_.find("v6_") == 0)
-        addr = asio::ip::address_v6::loopback();
-    else
-        isc_throw(XfroutError, "bad endpoint: " << impl_->file_path_);
-    uint16_t port = boost::lexical_cast<uint16_t>(impl_->file_path_.substr(3));
-    stream_protocol::endpoint ep(addr, port);
+        asio::ip::address addr;
+        if (impl_->file_path_.find("v4_") == 0)
+            addr = asio::ip::address_v4::loopback();
+        else if (impl_->file_path_.find("v6_") == 0)
+            addr = asio::ip::address_v6::loopback();
+        else
+            isc_throw(XfroutError, "bad endpoint: " << impl_->file_path_);
+        uint16_t port = boost::lexical_cast<uint16_t>(impl_->file_path_.substr(3));
+        stream_protocol::endpoint ep(addr, port);
 #endif
-    impl_->socket_.connect(ep, err);
-    if (err) {
-        isc_throw(XfroutError, "socket connect failed: " << err.message());
+        impl_->socket_.connect(ep);
+    } catch (const asio::system_error& err) {
+        isc_throw(XfroutError, "socket connect failed for " <<
+                  impl_->file_path_ << ": " << err.what());
     }
 }
 
@@ -103,8 +104,14 @@ XfroutClient::sendXfroutRequestInfo(const int tcp_sock,
 
     // TODO: this shouldn't be blocking send, even though it's unlikely to
     // block.
-    // converting the 16-bit word to network byte order.
-    const uint8_t lenbuf[2] = { msg_len >> 8, msg_len & 0xff };
+    // Converting the 16-bit word to network byte order.
+
+    // Splitting msg_len below performs something called a 'narrowing
+    // conversion' (conversion of uint16_t to uint8_t). C++0x (and GCC
+    // 4.7) requires explicit casting when a narrowing conversion is
+    // performed. For reference, see 8.5.4/6 of n3225.
+    const uint8_t lenbuf[2] = { static_cast<uint8_t>(msg_len >> 8),
+                                static_cast<uint8_t>(msg_len & 0xff) };
 #ifndef _WIN32
     if (send(impl_->socket_.native(), lenbuf, sizeof(lenbuf), 0) !=
         sizeof(lenbuf)) {
@@ -129,6 +136,7 @@ XfroutClient::sendXfroutRequestInfo(const int tcp_sock,
                   "failed to send XFR request data to xfrout module");
     }
 #endif
+
     return (0);
 }
 



More information about the bind10-changes mailing list