void DBClientMultiCommand::sendAll() {

    for ( deque<PendingCommand*>::iterator it = _pendingCommands.begin();
            it != _pendingCommands.end(); ++it ) {

        PendingCommand* command = *it;
        dassert( NULL == command->conn );

        try {
            // TODO: Figure out how to handle repl sets, configs
            dassert( command->endpoint.type() == ConnectionString::MASTER ||
                     command->endpoint.type() == ConnectionString::CUSTOM );
            command->conn = shardConnectionPool.get( command->endpoint, 0 /*timeout*/);

            if ( hasBatchWriteFeature( command->conn )
                    || !isBatchWriteCommand( command->cmdObj ) ) {
                // Do normal command dispatch
                sayAsCmd( command->conn, command->dbName, command->cmdObj );
            }
            else {
                // Sending a batch as safe writes necessarily blocks, so we can't do anything
                // here.  Instead we do the safe writes in recvAny(), which can block.
            }
        }
        catch ( const DBException& ex ) {
            command->status = ex.toStatus();
            if ( NULL != command->conn ) delete command->conn;
            command->conn = NULL;
        }
    }
}
    void DBClientMultiCommand::sendAll() {

        for ( deque<PendingCommand*>::iterator it = _pendingCommands.begin();
            it != _pendingCommands.end(); ++it ) {

            PendingCommand* command = *it;
            dassert( NULL == command->conn );

            try {
                dassert( command->endpoint.type() == ConnectionString::MASTER ||
                    command->endpoint.type() == ConnectionString::CUSTOM );

                // TODO: Fix the pool up to take millis directly
                int timeoutSecs = _timeoutMillis / 1000;
                command->conn = shardConnectionPool.get( command->endpoint, timeoutSecs );

                if ( hasBatchWriteFeature( command->conn )
                     || !isBatchWriteCommand( command->cmdObj ) ) {
                    // Do normal command dispatch
                    sayAsCmd( command->conn, command->dbName, command->cmdObj );
                }
                else {
                    // Sending a batch as safe writes necessarily blocks, so we can't do anything
                    // here.  Instead we do the safe writes in recvAny(), which can block.
                }
            }
            catch ( const DBException& ex ) {
                command->status = ex.toStatus();

                if ( NULL != command->conn ) {

                    // Confusingly, the pool needs to know about failed connections so that it can
                    // invalidate other connections which might be bad.  But if the connection
                    // doesn't seem bad, don't send it back, because we don't want to reuse it.
                    if ( !command->conn->isFailed() ) {
                        delete command->conn;
                    }
                    else {
                        shardConnectionPool.release( command->endpoint.toString(), command->conn );
                    }

                    command->conn = NULL;
                }
            }
        }
    }