From da9d2156e3137a9575aa0f7b1dc7d52dc4908737 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Wed, 19 Jun 2013 15:30:50 +0000 Subject: QPID-4931: Only allow broker to listen to a single address if "--port 0" specified - If more than one address is specified or implied by the defaults the broker will log a warning - This is intended to avoid testing problems where the broker fails to connect to the port of subsequent listening addresses git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1494656 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/SocketTransport.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/sys/SocketTransport.cpp') diff --git a/cpp/src/qpid/sys/SocketTransport.cpp b/cpp/src/qpid/sys/SocketTransport.cpp index 2e03d18d82..502aaa3bab 100644 --- a/cpp/src/qpid/sys/SocketTransport.cpp +++ b/cpp/src/qpid/sys/SocketTransport.cpp @@ -35,6 +35,7 @@ #include "qpid/sys/SystemInfo.h" #include +#include namespace qpid { namespace sys { @@ -130,9 +131,11 @@ void SocketAcceptor::addListener(Socket* socket) listeners.push_back(socket); } -uint16_t SocketAcceptor::listen(const std::vector& interfaces, const std::string& port, int backlog, const SocketFactory& factory) +uint16_t SocketAcceptor::listen(const std::vector& interfaces, uint16_t port, int backlog, const SocketFactory& factory) { std::vector addresses = expandInterfaces(interfaces); + std::string sport(boost::lexical_cast(port)); + if (addresses.empty()) { // We specified some interfaces, but couldn't find addresses for them QPID_LOG(warning, "TCP/TCP6: No specified network interfaces found: Not Listening"); @@ -142,7 +145,7 @@ uint16_t SocketAcceptor::listen(const std::vector& interfaces, cons int listeningPort = 0; for (unsigned i = 0; i& interfaces, cons listeningPort = lport; + // If we were told to figure out the port then only allow listening to one address + if (port==0) { + // Print warning if the user specified more than one interface + // or there if is another address for this one + if (sa.nextAddress() || addresses.size()>1 ) { + QPID_LOG(warning, "Specified port=0: Only listened to: " << sa.asString()); + } + break; + } + // Try any other resolved addresses while (sa.nextAddress()) { - // Hack to ensure that all listening connections are on the same port - sa.setAddrInfoPort(listeningPort); QPID_LOG(info, "Listening to: " << sa.asString()) Socket* s = factory(); uint16_t lport = s->listen(sa, backlog); -- cgit v1.2.1