Enhancement of logging in TcpTransport

The logging in TcpConnection and TcpListener is now more meaningful
and allows a better understanding of the log traces during postmortem
debugging.

Change-Id: I5f999920c5aa9c5acc73f2abbebf23e9aa5e7c06

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1548400 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
index 2db3f7a..70b0ad1 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
@@ -67,11 +67,15 @@
     capu::int32_t n;
     status_t result = mSocket->receive((capu::char_t*)buf->getBuffer(), buf->getSize(), n);
     if (result != ETCH_OK) {
-      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Receive() failed with error code " << result);
+      if (n == 0) {
+        ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(),  mHost.c_str() << ":" << mPort <<" => Connection has been closed by peer.");
+      } else {
+        ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Receive() failed with error code " << result);
+      }
       return result;
     }
     if (n <= 0) {
-      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(),  mHost.c_str() << ":" << mPort <<" => Connection closed for stack");
+      ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(),  mHost.c_str() << ":" << mPort <<" => Connection has been closed by peer.");
       return ETCH_ERROR;
     }
 
@@ -95,7 +99,8 @@
   //temporary socket in a listener
   if (reconnect && (mPort == 0) && (mHost.length() == 0)) {
     mMutexConnection.unlock();
-    return ETCH_ERROR;
+    //reconnect is not possible on listener side.
+    return ETCH_ENOT_SUPPORTED;
   }
   // if a reconnect but retries not allowed, then fail.
   if (reconnect && (mOptions.getReconnectDelay() == 0)) {
@@ -128,7 +133,10 @@
     }
     if (mSocket->connect((capu::char_t*) mHost.c_str(), mPort) == ETCH_OK) {
       mMutexConnection.unlock();
-      ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Connection established");
+      capu::char_t* remoteAddress = NULL;
+      status_t result = mSocket->getRemoteAddress(&remoteAddress);
+
+      ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Connection established to remote " << remoteAddress);
       return ETCH_OK;
     } else {
       mSocket->close();
@@ -269,13 +277,17 @@
 
     status = openSocket(!first);
     if (status != ETCH_OK) {
-      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Socket has not been successfully opened");
+      if (status == ETCH_ENOT_SUPPORTED) {
+        ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Connection to client closed.");
+      } else {
+        ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Socket could not be opened.");
+      }
       break;
     }
 
     status = setupSocket();
     if (status != ETCH_OK) {
-      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Socket has not been successfully opened");
+      ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Socket has not been successfully set up");
       close();
       break;
     }
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
index b34153e..fe48cba 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
@@ -149,7 +149,9 @@
     if (s == NULL)
       break;
     if (mSession != NULL) {
-      ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), "A connection has been accepted");
+      capu::char_t* remoteAddress = NULL;
+      status_t result = s->getRemoteAddress(&remoteAddress);
+      ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), "A new connection from " << remoteAddress << " has been accepted");
       mSession->sessionAccepted(s);
     } else {
       delete s;