Author: gsim
Date: Mon Oct 15 04:56:09 2007
New Revision: 584755

URL: http://svn.apache.org/viewvc?rev=584755&view=rev
Log:
Include information on the client connection in io traces.


Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOAcceptor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOAcceptor.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOAcceptor.cpp?rev=584755&r1=584754&r2=584755&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOAcceptor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/AsynchIOAcceptor.cpp Mon Oct 15 
04:56:09 2007
@@ -211,7 +211,7 @@
         framing::AMQFrame frame;
         try{
             while(frame.decode(in)) {
-                QPID_LOG(debug, "RECV: " << frame);
+                QPID_LOG(debug, "RECV [" << aio->getSocket().getPeerAddress() 
<< "]: " << frame);
                 inputHandler->received(frame);
             }
         }catch(const std::exception& e){
@@ -222,7 +222,7 @@
     }else{
         framing::ProtocolInitiation protocolInit;
         if(protocolInit.decode(in)){
-            QPID_LOG(debug, "INIT [" << aio << "]");
+            QPID_LOG(debug, "INIT [" << aio->getSocket().getPeerAddress() << 
"]");
             inputHandler->initiated(protocolInit);
             initiated = true;
         }
@@ -285,7 +285,7 @@
                        // Encode output frame  
                        frame.encode(out);
                        buffUsed += frameSize;
-                       QPID_LOG(debug, "SENT: " << frame);
+                       QPID_LOG(debug, "SENT [" << 
aio->getSocket().getPeerAddress() << "]: " << frame);
                        
                        if (frameQueue.empty())
                                break;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h?rev=584755&r1=584754&r2=584755&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h Mon Oct 15 04:56:09 2007
@@ -77,6 +77,17 @@
      */
     std::string getSockname() const;
 
+    /** Returns the "peer name" ie the address bound to 
+     * the remote end of the socket
+     */
+    std::string getPeername() const;
+
+    /** 
+     * Returns an address (host and port) for the remote end of the
+     * socket
+     */
+    std::string getPeerAddress() const;
+
     /** Accept a connection from a socket that is already listening
      * and has an incoming connection
      */

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?rev=584755&r1=584754&r2=584755&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Mon Oct 15 
04:56:09 2007
@@ -39,13 +39,46 @@
 
 class SocketPrivate {
 public:
-       SocketPrivate(int f = -1) :
-               fd(f)
-       {}
+    SocketPrivate(int f = -1) :
+            fd(f)
+    {}
+    
+    int fd;
 
-       int fd;
+    std::string getName(bool local, bool includeService = false) const;   
 };
 
+std::string SocketPrivate::getName(bool local, bool includeService) const
+{
+    ::sockaddr_storage name; // big enough for any socket address    
+    ::socklen_t namelen = sizeof(name);
+    
+    int result = -1;
+    if (local) {
+        result = ::getsockname(fd, (::sockaddr*)&name, &namelen);
+    } else {
+        result = ::getpeername(fd, (::sockaddr*)&name, &namelen);
+    }
+
+    if (result < 0)
+        throw QPID_POSIX_ERROR(errno);
+
+    char servName[NI_MAXSERV];
+    char dispName[NI_MAXHOST];
+    if (includeService) {
+        if (int rc=::getnameinfo((::sockaddr*)&name, namelen, dispName, 
sizeof(dispName), 
+                                 servName, sizeof(servName), 
+                                 NI_NUMERICHOST | NI_NUMERICSERV) != 0)
+            throw QPID_POSIX_ERROR(rc);
+        return std::string(dispName) + ":" + std::string(servName);
+
+    } else {
+        if (int rc=::getnameinfo((::sockaddr*)&name, namelen, dispName, 
sizeof(dispName), 0, 0, NI_NUMERICHOST) != 0)
+            throw QPID_POSIX_ERROR(rc);
+        return dispName;
+    }
+}
+
 Socket::Socket() :
        impl(new SocketPrivate)
 {
@@ -175,17 +208,17 @@
 
 std::string Socket::getSockname() const
 {
-    ::sockaddr_storage name; // big enough for any socket address    
-    ::socklen_t namelen = sizeof(name);
+    return impl->getName(true);
+}
 
-       const int& socket = impl->fd;
-    if (::getsockname(socket, (::sockaddr*)&name, &namelen) < 0)
-        throw QPID_POSIX_ERROR(errno);
-    
-    char dispName[NI_MAXHOST];
-    if (int rc=::getnameinfo((::sockaddr*)&name, namelen, dispName, 
sizeof(dispName), 0, 0, NI_NUMERICHOST) != 0)
-       throw QPID_POSIX_ERROR(rc);
-    return dispName;
+std::string Socket::getPeername() const
+{
+    return impl->getName(false);
+}
+
+std::string Socket::getPeerAddress() const
+{
+    return impl->getName(false, true);
 }
 
 int toFd(const SocketPrivate* s)


Reply via email to