Пример #1
0
void test1() {
    clock_t t;
    int i;
    chk_timermgr *mgr = chk_timermgr_new();

    t = clock();
    for (i = 0; i < N; ++i) {
        ids[i] = chk_timer_register(mgr, rand() * rand(), on_timeout_cb, NULL, 0);
    }
    printf("create time: %dms\n", (int)((clock()-t)*1000/CLOCKS_PER_SEC));

    t = clock();
    for (i = 0; i < N; ++i)
        chk_timer_unregister(ids[i]);
    printf("cancel time: %dms\n", (int)((clock()-t)*1000/CLOCKS_PER_SEC));

    t = clock();
    for (i = 0; i < N; ++i) {
        ids[i] = chk_timer_register(mgr, rand() * rand(), on_timeout_cb, NULL, 0);
    }
    printf("create time: %dms\n", (int)((clock()-t)*1000/CLOCKS_PER_SEC));

    t = clock();
    for (i = 0; i < N; ++i) {
        chk_timer_tick(mgr, i);
    }
    printf("update time: %dms\n", (int)((clock()-t)*1000/CLOCKS_PER_SEC));

    chk_timermgr_del(mgr);
}
Пример #2
0
void data_event_cb(chk_stream_socket *s,int32_t event,chk_bytebuffer *data) {
	chk_timer *t;
	if(!data) {		
		t = (chk_timer*)chk_stream_socket_getUd(s);
		chk_timer_unregister(t);
		chk_stream_socket_close(s);
	}else{
		++packet_count;
	}
}