qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject svn commit: r1128067 - in /qpid/trunk/qpid/cpp/src/qpid/sys: Socket.h posix/Socket.cpp windows/Socket.cpp
Date Thu, 26 May 2011 20:38:43 GMT
Author: astitcher
Date: Thu May 26 20:38:43 2011
New Revision: 1128067

URL: http://svn.apache.org/viewvc?rev=1128067&view=rev
Log:
NO-JIRA: Add cached localname as well as peername to Socket

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

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h?rev=1128067&r1=1128066&r2=1128067&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h Thu May 26 20:38:43 2011
@@ -93,7 +93,8 @@ private:
     void createSocket(const SocketAddress&) const;
 
     Socket(IOHandlePrivate*);
-    mutable std::string connectname;
+    mutable std::string localname;
+    mutable std::string peername;
     mutable bool nonblocking;
     mutable bool nodelay;
 };

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?rev=1128067&r1=1128066&r2=1128067&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Thu May 26 20:38:43 2011
@@ -122,7 +122,7 @@ void Socket::connect(const std::string& 
 
 void Socket::connect(const SocketAddress& addr) const
 {
-    connectname = addr.asString();
+    peername = addr.asString();
 
     createSocket(addr);
 
@@ -130,7 +130,7 @@ void Socket::connect(const SocketAddress
     // TODO the correct thing to do here is loop on failure until you've used all the returned
addresses
     if ((::connect(socket, getAddrInfo(addr).ai_addr, getAddrInfo(addr).ai_addrlen) <
0) &&
         (errno != EINPROGRESS)) {
-        throw Exception(QPID_MSG(strError(errno) << ": " << connectname));
+        throw Exception(QPID_MSG(strError(errno) << ": " << peername));
     }
     // When connecting to a port on the same host which no longer has
     // a process associated with it, the OS occasionally chooses the
@@ -147,7 +147,7 @@ void Socket::connect(const SocketAddress
     //
     if (getLocalAddress() == getPeerAddress()) {
         close();
-        throw Exception(QPID_MSG("Connection refused: " << connectname));
+        throw Exception(QPID_MSG("Connection refused: " << peername));
     }
 }
 
@@ -190,8 +190,11 @@ int Socket::listen(const SocketAddress& 
 Socket* Socket::accept() const
 {
     int afd = ::accept(impl->fd, 0, 0);
-    if ( afd >= 0)
-        return new Socket(new IOHandlePrivate(afd));
+    if ( afd >= 0) {
+        Socket* s = new Socket(new IOHandlePrivate(afd));
+        s->localname = localname;
+        return s;
+    }
     else if (errno == EAGAIN)
         return 0;
     else throw QPID_POSIX_ERROR(errno);
@@ -209,15 +212,18 @@ int Socket::write(const void *buf, size_
 
 std::string Socket::getPeerAddress() const
 {
-    if (connectname.empty()) {
-        connectname = getName(impl->fd, false);
+    if (peername.empty()) {
+        peername = getName(impl->fd, false);
     }
-    return connectname;
+    return peername;
 }
 
 std::string Socket::getLocalAddress() const
 {
-    return getName(impl->fd, true);
+    if (localname.empty()) {
+        localname = getName(impl->fd, true);
+    }
+    return localname;
 }
 
 int Socket::getError() const

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp?rev=1128067&r1=1128066&r2=1128067&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp Thu May 26 20:38:43 2011
@@ -178,7 +178,7 @@ Socket::connect(const SocketAddress& add
         addrs = addrs->ai_next;
     }
     if (error)
-        throw qpid::Exception(QPID_MSG(strError(error) << ": " << connectname));
+        throw qpid::Exception(QPID_MSG(strError(error) << ": " << peername));
 }
 
 void
@@ -241,14 +241,16 @@ Socket* Socket::accept() const
 
 std::string Socket::getPeerAddress() const
 {
-    if (!connectname.empty())
-        connectname = getName(impl->fd, false);
-    return connectname;
+    if (peername.empty())
+        peername = getName(impl->fd, false);
+    return peername;
 }
 
 std::string Socket::getLocalAddress() const
 {
-    return getName(impl->fd, true);
+    if (localname.empty())
+        localname = getName(impl->fd, true);
+    return localname;
 }
 
 int Socket::getError() const



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message