BIND 10 trac3160, updated. bd87ddb34aef27f3cc0620e1ddecd9093a360f08 [3160] Add IOEndpoint::toText()

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Sep 13 05:12:43 UTC 2013


The branch, trac3160 has been updated
       via  bd87ddb34aef27f3cc0620e1ddecd9093a360f08 (commit)
      from  6faa17ef4f22d11d3fc653680d073ac61197d6b3 (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 bd87ddb34aef27f3cc0620e1ddecd9093a360f08
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Sep 13 10:38:14 2013 +0530

    [3160] Add IOEndpoint::toText()

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

Summary of changes:
 src/lib/asiolink/io_endpoint.cc                |   19 +++++++++++++------
 src/lib/asiolink/io_endpoint.h                 |    3 +++
 src/lib/asiolink/tests/io_endpoint_unittest.cc |   10 ++++++++++
 3 files changed, 26 insertions(+), 6 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/asiolink/io_endpoint.cc b/src/lib/asiolink/io_endpoint.cc
index 2354521..edca58e 100644
--- a/src/lib/asiolink/io_endpoint.cc
+++ b/src/lib/asiolink/io_endpoint.cc
@@ -61,17 +61,24 @@ IOEndpoint::operator!=(const IOEndpoint& other) const {
     return (!operator==(other));
 }
 
-ostream&
-operator<<(ostream& os, const IOEndpoint& endpoint) {
-    if (endpoint.getFamily() == AF_INET6) {
-        os << "[" << endpoint.getAddress().toText() << "]";
+std::string
+IOEndpoint::toText() const {
+    std::string str;
+    if (getFamily() == AF_INET6) {
+        str.append("[" + getAddress().toText() + "]");
     } else {
         // In practice this should be AF_INET, but it's not guaranteed by
         // the interface.  We'll use the result of textual address
         // representation opaquely.
-        os << endpoint.getAddress().toText();
+        str.append(getAddress().toText());
     }
-    os << ":" << boost::lexical_cast<string>(endpoint.getPort());
+    str.append(":" + boost::lexical_cast<string>(getPort()));
+    return (str);
+}
+
+ostream&
+operator<<(ostream& os, const IOEndpoint& endpoint) {
+    os << endpoint.toText();
     return (os);
 }
 } // namespace asiolink
diff --git a/src/lib/asiolink/io_endpoint.h b/src/lib/asiolink/io_endpoint.h
index 89bc247..5bebf89 100644
--- a/src/lib/asiolink/io_endpoint.h
+++ b/src/lib/asiolink/io_endpoint.h
@@ -95,6 +95,9 @@ public:
     /// \brief Returns the address family of the endpoint.
     virtual short getFamily() const = 0;
 
+    /// \brief Convert the IOEndpoint to a string.
+    std::string toText() const;
+
     /// \brief Returns the address of the endpoint in the form of sockaddr
     /// structure.
     ///
diff --git a/src/lib/asiolink/tests/io_endpoint_unittest.cc b/src/lib/asiolink/tests/io_endpoint_unittest.cc
index 462a2fb..67dd904 100644
--- a/src/lib/asiolink/tests/io_endpoint_unittest.cc
+++ b/src/lib/asiolink/tests/io_endpoint_unittest.cc
@@ -260,6 +260,16 @@ class TestIOEndpoint : public IOEndpoint {
     }
 };
 
+TEST(IOEndpointTest, toText) {
+    // UDP/IPv4
+    ConstIOEndpointPtr ep(IOEndpoint::create(IPPROTO_UDP,
+                                             IOAddress("192.0.2.1"), 53210));
+    EXPECT_EQ("192.0.2.1:53210", ep->toText());
+
+    // More thorough tests are done in operator<< test below, which
+    // wraps around toText().
+}
+
 void
 checkEndpointText(const std::string& expected, const IOEndpoint& ep) {
     std::ostringstream oss;



More information about the bind10-changes mailing list