コード例 #1
0
ファイル: genesis.c プロジェクト: suzp1984/genesis
int main(int argc, char* argv[])
{
    Allocator* alloc = allocator_nginx_create(1024);
    Config* config = config_xml_expat_create();
    
    config_load(config, "../../../src/app/genesis-config.xml");
    Reactor* reactor = reactor_create(config, alloc);

    SourcesManager* sources_manager = NULL;
    reactor_get_sources_manager(reactor, &sources_manager);
    MainLoop* main_loop = NULL;
    reactor_get_main_loop(reactor, &main_loop);
    Source* timer_source = source_timer_create(2000, test_timer, (void*)reactor);
    //sources_manager_add_source(sources_manager, timer_source);
    logger_debug(reactor->logger, "sources_count = %d", sources_manager_get_count(sources_manager));
    main_loop_add_source(main_loop, timer_source);
    logger_debug(reactor->logger, "sources_count = %d", sources_manager_get_count(sources_manager));

    reactor_run(reactor);
    
    reactor_destroy(reactor);

    config_destroy(config);

    allocator_destroy(alloc);

    return 0;
}
コード例 #2
0
ファイル: test_wsconn.c プロジェクト: gaccob/gbase
int
test_ws_server() {
    con_table = idtable_create(1024);
    assert(con_table);

    r = reactor_create();
    assert(r);

    acc_t* acc = acc_create(r);
    assert(acc);
    acc_set_read_func(acc, _accept_read, NULL);

    struct sockaddr_in addr;
    int res = sock_addr_aton(WS_IP, WS_PORT, &addr);
    assert(res == 0);

    res = acc_start(acc, (struct sockaddr*)&addr);
    assert(res == 0);

    while (1) {
        res = reactor_dispatch(r, 1);
        if(res < 0) return -1;
        if(res == 0) usleep(100);
    }

    acc_stop(acc);
    acc_release(acc);
    for (int i = 0; i < 1024; i++) {
        WSCtx* ctx = idtable_get(con_table, i);
        if (ctx) {
            wsconn_release(ctx->con);
            FREE(ctx);
        }
    }
    idtable_release(con_table);
    reactor_release(r);
    return 0;
}