summaryrefslogtreecommitdiff
path: root/qpid/cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2011-05-26 20:38:43 +0000
committerAndrew Stitcher <astitcher@apache.org>2011-05-26 20:38:43 +0000
commitbb7ac8e04aa47d37b19dc6f9669dcc2afb93bb2f (patch)
treed7fb4934c74c8f4baa8661d54462caec46caa6c7 /qpid/cpp
parent517f85dcab8e9de7196716e2bf456d7fa6c6d68d (diff)
downloadqpid-python-bb7ac8e04aa47d37b19dc6f9669dcc2afb93bb2f.tar.gz
NO-JIRA: Add cached localname as well as peername to Socket
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1128067 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/src/qpid/sys/Socket.h3
-rw-r--r--qpid/cpp/src/qpid/sys/posix/Socket.cpp24
-rwxr-xr-xqpid/cpp/src/qpid/sys/windows/Socket.cpp12
3 files changed, 24 insertions, 15 deletions
diff --git a/qpid/cpp/src/qpid/sys/Socket.h b/qpid/cpp/src/qpid/sys/Socket.h
index db4cab4c15..9f62f3be1c 100644
--- a/qpid/cpp/src/qpid/sys/Socket.h
+++ b/qpid/cpp/src/qpid/sys/Socket.h
@@ -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;
};
diff --git a/qpid/cpp/src/qpid/sys/posix/Socket.cpp b/qpid/cpp/src/qpid/sys/posix/Socket.cpp
index 1b25a25824..be757ba00f 100644
--- a/qpid/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/qpid/cpp/src/qpid/sys/posix/Socket.cpp
@@ -122,7 +122,7 @@ void Socket::connect(const std::string& host, const std::string& port) const
void Socket::connect(const SocketAddress& addr) const
{
- connectname = addr.asString();
+ peername = addr.asString();
createSocket(addr);
@@ -130,7 +130,7 @@ void Socket::connect(const SocketAddress& addr) const
// 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& addr) const
//
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& sa, int backlog) const
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_t count) const
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
diff --git a/qpid/cpp/src/qpid/sys/windows/Socket.cpp b/qpid/cpp/src/qpid/sys/windows/Socket.cpp
index 90984639a2..fa47308cc2 100755
--- a/qpid/cpp/src/qpid/sys/windows/Socket.cpp
+++ b/qpid/cpp/src/qpid/sys/windows/Socket.cpp
@@ -178,7 +178,7 @@ Socket::connect(const SocketAddress& addr) const
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