face: Implementing close operation and many related fixes in TcpFace and TcpChannel

Change-Id: Ib6b751e80454e149bf94f3867663d5e705cbf4a0
refs: #1250, #1248
diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp
index 999f9c9..e94747f 100644
--- a/daemon/face/tcp-channel.hpp
+++ b/daemon/face/tcp-channel.hpp
@@ -52,8 +52,11 @@
   /**
    * \brief Enable listening on the local endpoint, accept connections,
    *        and create faces when remote host makes a connection
-   * \param backlog The maximum length of the queue of pending incoming
-   *        connections
+   * \param onFaceCreated  Callback to notify successful creation of the face
+   * \param onAcceptFailed Callback to notify when channel fails (accept call
+   *                       returns an error)
+   * \param backlog        The maximum length of the queue of pending incoming
+   *                       connections
    */
   void
   listen(const FaceCreatedCallback& onFaceCreated,
@@ -85,6 +88,12 @@
           const FaceCreatedCallback& onFaceCreated,
           const ConnectFailedCallback& onConnectFailed,
           const time::Duration& timeout = time::seconds(4));
+
+  /**
+   * \brief Get number of faces in the channel
+   */
+  size_t
+  size() const;  
   
 private:
   void
@@ -92,6 +101,9 @@
              const FaceCreatedCallback& onFaceCreated);
 
   void
+  afterFaceFailed(tcp::Endpoint &endpoint);
+
+  void
   handleSuccessfulAccept(const boost::system::error_code& error,
                          const shared_ptr<boost::asio::ip::tcp::socket>& socket,
                          const FaceCreatedCallback& onFaceCreated,
@@ -118,7 +130,7 @@
                           const FaceCreatedCallback& onFaceCreated,
                           const ConnectFailedCallback& onConnectFailed,
                           const shared_ptr<boost::asio::ip::tcp::resolver>& resolver);
-  
+
 private:
   boost::asio::io_service& m_ioService;
   tcp::Endpoint m_localEndpoint;