You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2014/07/01 21:12:42 UTC

svn commit: r1607167 - /qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp

Author: astitcher
Date: Tue Jul  1 19:12:42 2014
New Revision: 1607167

URL: http://svn.apache.org/r1607167
Log:
QPID-5859: Fix to allow listening to some interfaces to fail
- but still listen to the succeeding ones

Modified:
    qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp?rev=1607167&r1=1607166&r2=1607167&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/SocketTransport.cpp Tue Jul  1 19:12:42 2014
@@ -147,33 +147,29 @@ uint16_t SocketAcceptor::listen(const st
         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;
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org