bool DBClientCursor::init() { Message toSend; if ( !cursorId ) { assembleRequest( ns, query, nToReturn, nToSkip, fieldsToReturn, opts, toSend ); } else { BufBuilder b; b.append( opts ); b.append( ns.c_str() ); b.append( nToReturn ); b.append( cursorId ); toSend.setData( dbGetMore, b.buf(), b.len() ); } if ( !connector->call( toSend, *m, false ) ) return false; dataReceived(); return true; }
//============================================================================= // Base beacon //============================================================================= static RU32 RPAL_THREAD_FUNC thread_beacon ( RPVOID context ) { RU32 status = 0; rList requests = NULL; rList responses = NULL; rIterator ite = NULL; rpcm_tag tag = 0; rpcm_type type = 0; rSequence msg = NULL; RPU8 crashContext = NULL; RU32 crashContextSize = 0; RU8 defaultCrashContext = 1; UNREFERENCED_PARAMETER( context ); // First let's check if we have a crash context already present // which would indicate we did not shut down properly if( !acquireCrashContextPresent( &crashContext, &crashContextSize ) ) { crashContext = NULL; crashContextSize = 0; } // Set a default crashContext to be removed before exiting setCrashContext( &defaultCrashContext, sizeof( defaultCrashContext ) ); while( !rEvent_wait( g_hcpContext.isBeaconTimeToStop, 0 ) ) { if( 0 == g_hcpContext.beaconTimeout ) { // This is the default timeout to re-establish contact home g_hcpContext.beaconTimeout = RP_HCP_CONFIG_DEFAULT_BEACON_TIMEOUT_INIT; requests = assembleRequest( crashContext, crashContextSize ); // If we just sent a crash context, free it so we don't keep sending it if( NULL != crashContext ) { rpal_memory_free( crashContext ); crashContext = NULL; crashContextSize = 0; } if( NULL != requests && doBeacon( RP_HCP_MODULE_ID_HCP, requests, &responses ) && NULL != responses ) { // This is the default beacon timeout when contact is already established g_hcpContext.beaconTimeout = RP_HCP_CONFIG_DEFAULT_BEACON_TIMEOUT; // Go through the response list of messages if( NULL != ( ite = rIterator_new( responses ) ) ) { while( rIterator_next( ite, &tag, &type, &msg, NULL ) ) { // We ignore non-messages for forward compat if( RP_TAGS_MESSAGE == tag && RPCM_SEQUENCE == type ) { processMessage( msg ); } } rIterator_free( ite ); } } // Free resources. IF_VALID_DO( requests, rList_free ); requests = NULL; IF_VALID_DO( responses, rList_free ); responses = NULL; } // Sleep for 1 second, we aproximate beacon times rpal_thread_sleep( 1 * 1000 ); if( 0 != g_hcpContext.beaconTimeout ){ g_hcpContext.beaconTimeout--; } } return status; }