node+transport: Fixing bug that prevented reconnection to the forwarder after being disconnected for some reason

tools/ndnputcatchunks shows an example how to design a daemon
application that is resilient to the local daemon shutdowns/restarts.

Note that when local forwarder disconnects, all pending interests and
registered prefixes will get flushed.

Change-Id: I2933e2b5d6fd8420de4f055e53c748dbd00cabe9
diff --git a/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
index 5aca79e..cd00a46 100644
--- a/src/transport/unix-transport.cpp
+++ b/src/transport/unix-transport.cpp
@@ -61,6 +61,7 @@
       {
         // may need to throw exception
         transport_.isConnected_ = false;
+        transport_.close();
         throw Transport::Error(error, "error while connecting to the forwarder");
       }
   }
@@ -82,14 +83,15 @@
   {
     if (!connectionInProgress_) {
       connectionInProgress_ = true;
-      socket_.open();
-      socket_.async_connect(protocol::endpoint(transport_.unixSocket_),
-                            func_lib::bind(&Impl::connectHandler, this, _1));
 
       // Wait at most 4 seconds to connect
       /// @todo Decide whether this number should be configurable
       connectTimer_.expires_from_now(boost::posix_time::seconds(4));
       connectTimer_.async_wait(func_lib::bind(&Impl::connectTimeoutHandler, this, _1));
+      
+      socket_.open();
+      socket_.async_connect(protocol::endpoint(transport_.unixSocket_),
+                            func_lib::bind(&Impl::connectHandler, this, _1));
     }
   }