/* Thread routine to calculate the distance for a given broker */ pal_thread_ret_t PAL_THREAD_CALL tspGetBrokerDistance(void *threadarg) { tBrokerTimingThreadArg *arguments = NULL; tBrokerList *broker = NULL; tConf *conf = NULL; tRedirectStatus status = TSP_REDIRECT_OK; unsigned int distance = 0; /* The thread needs a broker argument to work with */ if (threadarg == NULL) { pal_thread_exit((pal_thread_ret_t)(-1)); return (pal_thread_ret_t)(-1); } /* Unwrap the arguments */ arguments = (tBrokerTimingThreadArg *)threadarg; broker = (tBrokerList *)arguments->broker; conf = (tConf *)arguments->conf; /* Perform the echo request, calculating the distance */ status = tspDoEchoRequest(broker->address, broker->address_type, conf, &distance); /* Set the calculated distance in the broker list element */ broker->distance = distance; /* Make the status available on join */ pal_thread_exit((pal_thread_ret_t)status); return (pal_thread_ret_t)status; }
// -------------------------------------------------------------------------- // _ka_start_thread: Private worker thread function used to run the keep- // alive processing. Calls the IEE_process function until it returns. // // Parameters: // arg: Opaque pointer to the keepalive engine. // // Return value: // The keepalive engine final status. // pal_thread_ret_t PAL_THREAD_CALL _ka_start_thread( void *arg ) { PKA_ENGINE_PARMS p_ka_engine = (PKA_ENGINE_PARMS)arg; iee_ret_t iee_ret; // Check input pointer. if( p_ka_engine != NULL ) { // Let the ICMP echo engine process the keepalive echo messages. iee_ret = IEE_process( p_ka_engine->p_echo_engine ); switch( iee_ret ) { case IEE_SUCCESS: // Keepalive processing stopped. // Most probable cause: KA_stop() was invoked. p_ka_engine->ka_status = KA_STAT_FIN_SUCCESS; LOG_MESSAGE( LOG_LEVEL_3, ELInfo, STR_KA_STOP_INFO_CAUSE STR_KA_EXPLICIT_STOP ); break; case IEE_GENERAL_ECHO_TIMEOUT: // Keepalive timeout detected! p_ka_engine->ka_status = KA_STAT_FIN_TIMEOUT; LOG_MESSAGE( LOG_LEVEL_1, ELWarning, STR_KA_STOP_INFO_CAUSE STR_KA_GENERAL_TIMEOUT ); break; case IEE_INVALID_PARMS: // Input error. p_ka_engine->ka_status = KA_STAT_FIN_ERROR; LOG_MESSAGE( LOG_LEVEL_1, ELError, STR_KA_STOP_INFO_CAUSE STR_GEN_INVALID_POINTER ); break; case IEE_GENERAL_ECHO_ERROR: // Keepalive processing error. p_ka_engine->ka_status = KA_STAT_FIN_ERROR; LOG_MESSAGE( LOG_LEVEL_1, ELError, STR_KA_STOP_INFO_CAUSE STR_GEN_NETWORK_ERROR ); break; default: // Unknown/Unhandled ERROR. p_ka_engine->ka_status = KA_STAT_FIN_ERROR; LOG_MESSAGE( LOG_LEVEL_1, ELError, STR_KA_STOP_INFO_CAUSE STR_GEN_UNKNOWN_ERROR ); break; } } else { // Invalid pointer input. LOG_MESSAGE( LOG_LEVEL_1, ELError, STR_KA_STOP_INFO_CAUSE STR_GEN_INVALID_POINTER ); } // Exit the thread. pal_thread_exit( 0 ); return 0; }