fix for https://issues.apache.org/jira/browse/AMQCPP-358 on 3.2.x fixes branch.

git-svn-id: https://svn.apache.org/repos/asf/activemq/activemq-cpp/branches/activemq-cpp-3.2.x@1086808 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp b/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
index 7f123f4..a1a168c 100644
--- a/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
+++ b/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
@@ -489,7 +489,21 @@
 
     synchronized( &reconnectMutex ) {
         if( this->connectedTransport == NULL && !closed && started ) {
-            result = true;
+
+            int reconnectAttempts = 0;
+            if( firstConnection ) {
+                if( startupMaxReconnectAttempts != 0 ) {
+                    reconnectAttempts = startupMaxReconnectAttempts;
+                }
+            }
+
+            if( reconnectAttempts == 0 ) {
+                reconnectAttempts = maxReconnectAttempts;
+            }
+
+            if( reconnectAttempts > 0 && connectFailures < reconnectAttempts ) {
+                result = true;
+            }
         }
     }
 
@@ -566,9 +580,6 @@
 
                 try {
 
-                    //std::cout << "Failover: Attempting to connect to: "
-                    //          << uri.toString() << std::endl;
-
                     transport = createTransport( uri );
                     transport->setTransportListener( myTransportListener.get() );
                     transport->start();
@@ -579,8 +590,6 @@
 
                 } catch( Exception& e ) {
                     e.setMark( __FILE__, __LINE__ );
-                    //std::cout << "Failover: Failed while attempting to connect to: "
-                    //          << uri.toString() << std::endl;
 
                     if( transport != NULL ) {
                         if( this->disposedListener != NULL ) {
@@ -633,9 +642,6 @@
                     firstConnection = false;
                 }
 
-                //std::cout << "Failover: Successfully connected to Broker at: "
-                //          << connectedTransportURI->toString() << std::endl;
-
                 return false;
             }
         }
@@ -684,8 +690,6 @@
     if( !closed ) {
 
         synchronized( &sleepMutex ) {
-            //std::cout << "Failover: Trying again in "
-            //          << reconnectDelay << "Milliseconds." << std::endl;
             sleepMutex.wait( (unsigned int)reconnectDelay );
         }