예제 #1
0
파일: kaa_logging.c 프로젝트: Kirill380/kaa
/** Handles timeout event. Must be called if timeout is occurred. */
static void handle_timeout(kaa_log_collector_t *self)
{
    // TODO(KAA-982): Use asserts
    if (!self || !self->timeouts) {
        return;
    }

    kaa_error_t err = ext_log_upload_strategy_on_timeout(self->log_upload_strategy_context);

    bool expire_every_entry = (err == KAA_ERR_EVENT_NOT_ATTACHED);

    if (expire_every_entry) {
        /* Upload strategy decided to switch an access point. All pending logs are now deemed as
         * timeouted.
         */
        KAA_LOG_INFO(self->logger, KAA_ERR_NONE, "Access point has been switched. All buckets are expired.");
    }

    for (kaa_list_node_t *it = kaa_list_begin(self->timeouts); it; it = kaa_list_next(it)) {
        timeout_info_t *info = kaa_list_get_data(it);

        if (expire_every_entry || !info->deadline) {
            ext_log_storage_unmark_by_bucket_id(self->log_storage_context, info->log_bucket_id);
            if (self->log_delivery_listeners.on_timeout) {
                kaa_log_bucket_info_t log_bucket_info = {
                    .bucket_id = info->log_bucket_id,
                    .log_count = info->log_count,
                };

                self->log_delivery_listeners.on_timeout(self->log_delivery_listeners.ctx,
                        &log_bucket_info);
            }
        }
    }
예제 #2
0
파일: kaa_logging.c 프로젝트: xwiz/kaa
static bool is_timeout(kaa_log_collector_t *self)
{
    KAA_RETURN_IF_NIL2(self, self->timeouts, false);

    bool is_timeout = false;
    kaa_time_t now = KAA_TIME();

    kaa_list_node_t *it = kaa_list_begin(self->timeouts);
    while (it) {
        timeout_info_t *info = (timeout_info_t *)kaa_list_get_data(it);
        if (now >= info->timeout) {
            KAA_LOG_WARN(self->logger, KAA_ERR_TIMEOUT, "Log delivery timeout occurred (bucket_id %u)", info->log_bucket_id);
            is_timeout = true;
            break;
        }
        it = kaa_list_next(it);
    }

    if (is_timeout) {
        it = kaa_list_begin(self->timeouts);
        while (it) {
            timeout_info_t *info = (timeout_info_t *)kaa_list_get_data(it);
            ext_log_storage_unmark_by_bucket_id(self->log_storage_context, info->log_bucket_id);
            it = kaa_list_next(it);
        }

        kaa_list_clear(self->timeouts, NULL);
        ext_log_upload_strategy_on_timeout(self->log_upload_strategy_context);
    }

    return is_timeout;
}