ConnectionBase* ConnBoshMultStat::getConnection() { if( m_openRequests > 0 && m_openRequests >= m_maxOpenRequests ) { m_logInstance.warn( LogAreaClassConnectionBOSH, "Too many requests already open. Cannot send." ); return 0; } ConnectionBase* conn = 0; switch( m_connMode ) { case ModePipelining: if( !m_activeConnections.empty() ) { m_logInstance.dbg( LogAreaClassConnectionBOSH, "Using default connection for Pipelining." ); return m_activeConnections.front(); } else if( !m_connectionPool.empty() ) { m_logInstance.warn( LogAreaClassConnectionBOSH, "Pipelining selected, but no connection open. Opening one." ); return activateConnection(); } else m_logInstance.warn( LogAreaClassConnectionBOSH, "No available connections to pipeline on." ); break; case ModeLegacyHTTP: case ModePersistentHTTP: { if( !m_connectionPool.empty() ) { m_logInstance.dbg( LogAreaClassConnectionBOSH, "LegacyHTTP/PersistentHTTP selected, " "using connection from pool." ); return activateConnection(); } else if( !m_activeConnections.empty() ) { m_logInstance.dbg( LogAreaClassConnectionBOSH, "No connections in pool, creating a new one." ); conn = m_activeConnections.front()->newInstance(); conn->registerConnectionDataHandler( this ); m_connectionPool.push_back( conn ); conn->connect(); } else m_logInstance.warn( LogAreaClassConnectionBOSH, "No available connections to send on." ); break; } } return 0; }
ConnectionBase* ConnBoshMultStat::activateConnection() { ConnectionBase* conn = m_connectionPool.front(); m_connectionPool.pop_front(); if( conn->state() == StateConnected ) { m_activeConnections.push_back( conn ); return conn; } m_logInstance.dbg( LogAreaClassConnectionBOSH, "Connecting pooled connection." ); m_connectionPool.push_back( conn ); conn->connect(); return 0; }