summaryrefslogtreecommitdiff
path: root/qpid/cpp/src
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2014-07-01 19:12:42 +0000
committerAndrew Stitcher <astitcher@apache.org>2014-07-01 19:12:42 +0000
commit91e76353f4d664476cf391ed2a5c678c87301dea (patch)
treeda90eaac4644f80cd5c65056f758068b124b1ce8 /qpid/cpp/src
parentc1ed3d54c1132c2810e907d87ecec7f5491b118b (diff)
downloadqpid-python-91e76353f4d664476cf391ed2a5c678c87301dea.tar.gz
QPID-5859: Fix to allow listening to some interfaces to fail
- but still listen to the succeeding ones git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1607167 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r--qpid/cpp/src/qpid/sys/SocketTransport.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/qpid/cpp/src/qpid/sys/SocketTransport.cpp b/qpid/cpp/src/qpid/sys/SocketTransport.cpp
index 502aaa3bab..86c9d301e9 100644
--- a/qpid/cpp/src/qpid/sys/SocketTransport.cpp
+++ b/qpid/cpp/src/qpid/sys/SocketTransport.cpp
@@ -147,33 +147,29 @@ uint16_t SocketAcceptor::listen(const std::vector<std::string>& interfaces, uint
QPID_LOG(debug, "Using interface: " << addresses[i]);
SocketAddress sa(addresses[i], sport);
- // We must have at least one resolved address
- QPID_LOG(info, "Listening to: " << sa.asString())
- Socket* s = factory();
- uint16_t lport = s->listen(sa, backlog);
- QPID_LOG(debug, "Listened to: " << lport);
- addListener(s);
-
- 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 ) {
+ do {
+ try {
+ // If we were told to figure out the port then only allow listening to one address
+ if (port==0 && listeningPort!=0) {
+ // Print warning if the user specified more than one interface
QPID_LOG(warning, "Specified port=0: Only listened to: " << sa.asString());
+ return listeningPort;
}
- break;
- }
- // Try any other resolved addresses
- while (sa.nextAddress()) {
- QPID_LOG(info, "Listening to: " << sa.asString())
- Socket* s = factory();
+ QPID_LOG(info, "Listening to: " << sa.asString());
+ std::auto_ptr<Socket> s(factory());
uint16_t lport = s->listen(sa, backlog);
QPID_LOG(debug, "Listened to: " << lport);
- addListener(s);
+ addListener(s.release());
+
+ if (listeningPort==0) listeningPort = lport;
+ } catch (std::exception& e) {
+ QPID_LOG(warning, "Couldn't listen to: " << sa.asString() << ": " << e.what());
}
+ } while (sa.nextAddress());
+ }
+ if (listeningPort==0) {
+ throw Exception("Couldn't find any network address to listen to");
}
return listeningPort;
}