Exemple #1
0
int main(int argc, char** argv)
{
	struct heaptimer_t* timer;
	struct task_t* t;
	struct task_step_t* t1, *t2, *t3;
	struct timeval timeout;
	struct timeval tv;

    int32_t loop = argc > 1 ? atoi(argv[1]) : 3;

    cp = curl_pool_init();
    assert(cp);

    timer = timer_init();
    assert(timer);

    t = task_init(on_success, on_fail, (void*)&loop);
    assert(t);

    t1 = task_step_init(t1_run);
    assert(t1);
    task_push_back_step(t, t1);
    id = task_step_id(t1);

    t2 = task_step_init(t2_run);
    assert(t2);
    task_push_back_step(t, t2);

    t3 = task_step_init(t3_run);
    assert(t3);
    task_push_back_step(t, t3);

    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    task_run(t, timer, &timeout);

    while (1) {
        if (curl_pool_running_count(cp) > 0) {
            curl_pool_run(cp);
        }

        util_gettimeofday(&tv, NULL);
        timer_poll(timer, &tv);

        if (task_finished(t) == 0) {
            break;
        }
    }

    task_release(t);
    timer_release(timer);
    curl_pool_release(cp);
    return 0;
}
Exemple #2
0
int
test_logic_task(const char* param) {
    timerheap_t* timer = timer_create_heap();
    if (!timer) {
        fprintf(stderr, "timer create fail\n");
        return -1;
    }

    _curl_pool = curlp_create();
    if (!_curl_pool) {
        fprintf(stderr, "curl create fail\n");
        timer_release(timer);
        return -1;
    }

    task_t* t = task_create(on_success, on_fail, NULL);
    if (!t) {
        fprintf(stderr, "task create fail\n");
        timer_release(timer);
        curlp_release(_curl_pool);
        return -1;
    }

    struct timeval timeout;
    struct timeval tv;

    t1_param_t p;
    p.loop = (param ? atoi(param) : 3);
    task_step_t* t1 = task_step_create(t1_run, (void*)&p);
    task_step_t* t2 = task_step_create(t2_run, NULL);
    task_step_t* t3 = task_step_create(t3_run, NULL);
    if (!t1 || !t2 || !t3) {
        fprintf(stderr, "task step create fail\n");
        if (t1) task_step_release(t1);
        if (t2) task_step_release(t2);
        if (t3) task_step_release(t3);
        task_release(t);
        timer_release(timer);
        curlp_release(_curl_pool);
        return -1;
    }

    task_push_back_step(t, t1);
    _task_step_id = task_step_id(t1);
    task_push_back_step(t, t2);
    task_push_back_step(t, t3);

    timeout.tv_sec = 3;
    timeout.tv_usec = 0;
    task_run(t, timer, &timeout);

    while (1) {
        if (curlp_running_count(_curl_pool) > 0) {
            curlp_poll(_curl_pool);
        }
        gettimeofday(&tv, NULL);
        timer_poll(timer, &tv);
        if (task_is_finished(t) == 0) {
            break;
        }
    }

    task_release(t);
    timer_release(timer);
    curlp_release(_curl_pool);
    return 0;
}