summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/sys/SocketTransport.cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2013-06-19 15:30:50 +0000
committerAndrew Stitcher <astitcher@apache.org>2013-06-19 15:30:50 +0000
commitda9d2156e3137a9575aa0f7b1dc7d52dc4908737 (patch)
tree68b910671eaaac784ca9a3837ab0466fa64e277a /cpp/src/qpid/sys/SocketTransport.cpp
parent56e808fda39091678bfa4db8d9ef9a0148898c28 (diff)
downloadqpid-python-da9d2156e3137a9575aa0f7b1dc7d52dc4908737.tar.gz
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
Diffstat (limited to 'cpp/src/qpid/sys/SocketTransport.cpp')
-rw-r--r--cpp/src/qpid/sys/SocketTransport.cpp19
1 files changed, 15 insertions, 4 deletions
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 <boost/bind.hpp>
+#include <boost/lexical_cast.hpp>
namespace qpid {
namespace sys {
@@ -130,9 +131,11 @@ void SocketAcceptor::addListener(Socket* socket)
listeners.push_back(socket);
}
-uint16_t SocketAcceptor::listen(const std::vector<std::string>& interfaces, const std::string& port, int backlog, const SocketFactory& factory)
+uint16_t SocketAcceptor::listen(const std::vector<std::string>& interfaces, uint16_t port, int backlog, const SocketFactory& factory)
{
std::vector<std::string> addresses = expandInterfaces(interfaces);
+ std::string sport(boost::lexical_cast<std::string>(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<std::string>& interfaces, cons
int listeningPort = 0;
for (unsigned i = 0; i<addresses.size(); ++i) {
QPID_LOG(debug, "Using interface: " << addresses[i]);
- SocketAddress sa(addresses[i], port);
+ SocketAddress sa(addresses[i], sport);
// We must have at least one resolved address
QPID_LOG(info, "Listening to: " << sa.asString())
@@ -153,10 +156,18 @@ uint16_t SocketAcceptor::listen(const std::vector<std::string>& 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);