transport: minor refactoring

Change-Id: Ieebf3d58e3094b60978857eb35934e1980734fc8
diff --git a/ndn-cxx/transport/tcp-transport.cpp b/ndn-cxx/transport/tcp-transport.cpp
index 79f53fa..bccbe9d 100644
--- a/ndn-cxx/transport/tcp-transport.cpp
+++ b/ndn-cxx/transport/tcp-transport.cpp
@@ -48,30 +48,30 @@
 std::pair<std::string, std::string>
 TcpTransport::getSocketHostAndPortFromUri(const std::string& uriString)
 {
+  // Default host and port.
   std::string host = "localhost";
   std::string port = "6363";
 
-  if (uriString.empty()) {
-    return {host, port};
-  }
+  // Use host and port from the provided URI, if valid.
+  if (!uriString.empty()) {
+    try {
+      const FaceUri uri(uriString);
 
-  try {
-    const FaceUri uri(uriString);
+      const auto& scheme = uri.getScheme();
+      if (scheme != "tcp" && scheme != "tcp4" && scheme != "tcp6") {
+        NDN_THROW(Error("Cannot create TcpTransport from \"" + scheme + "\" URI"));
+      }
 
-    const auto& scheme = uri.getScheme();
-    if (scheme != "tcp" && scheme != "tcp4" && scheme != "tcp6") {
-      NDN_THROW(Error("Cannot create TcpTransport from \"" + scheme + "\" URI"));
+      if (!uri.getHost().empty()) {
+        host = uri.getHost();
+      }
+      if (!uri.getPort().empty()) {
+        port = uri.getPort();
+      }
     }
-
-    if (!uri.getHost().empty()) {
-      host = uri.getHost();
+    catch (const FaceUri::Error& error) {
+      NDN_THROW_NESTED(Error(error.what()));
     }
-    if (!uri.getPort().empty()) {
-      port = uri.getPort();
-    }
-  }
-  catch (const FaceUri::Error& error) {
-    NDN_THROW_NESTED(Error(error.what()));
   }
 
   return {host, port};
diff --git a/ndn-cxx/transport/unix-transport.cpp b/ndn-cxx/transport/unix-transport.cpp
index 33f3919..b74ee00 100644
--- a/ndn-cxx/transport/unix-transport.cpp
+++ b/ndn-cxx/transport/unix-transport.cpp
@@ -40,33 +40,29 @@
 std::string
 UnixTransport::getSocketNameFromUri(const std::string& uriString)
 {
-  // Assume the default nfd.sock location.
+  // Use path from the provided URI, if valid.
+  if (!uriString.empty()) {
+    try {
+      const FaceUri uri(uriString);
+      if (uri.getScheme() != "unix") {
+        NDN_THROW(Error("Cannot create UnixTransport from \"" + uri.getScheme() + "\" URI"));
+      }
+      if (!uri.getPath().empty()) {
+        return uri.getPath();
+      }
+    }
+    catch (const FaceUri::Error& error) {
+      NDN_THROW_NESTED(Error(error.what()));
+    }
+  }
+
+  // Otherwise, use the default nfd.sock location.
+  return
 #ifdef __linux__
-  std::string path = "/run/nfd.sock";
+    "/run/nfd.sock";
 #else
-  std::string path = "/var/run/nfd.sock";
+    "/var/run/nfd.sock";
 #endif // __linux__
-
-  if (uriString.empty()) {
-    return path;
-  }
-
-  try {
-    const FaceUri uri(uriString);
-
-    if (uri.getScheme() != "unix") {
-      NDN_THROW(Error("Cannot create UnixTransport from \"" + uri.getScheme() + "\" URI"));
-    }
-
-    if (!uri.getPath().empty()) {
-      path = uri.getPath();
-    }
-  }
-  catch (const FaceUri::Error& error) {
-    NDN_THROW_NESTED(Error(error.what()));
-  }
-
-  return path;
 }
 
 shared_ptr<UnixTransport>