Example #1
0
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;
}
Example #2
0
void reactor_stop(struct Reactor *reactor)
{
    if (!PRIV(reactor)->map || !PRIV(reactor)->reactor_fd)
        return;
    for (int i = 0; i <= reactor->maxfd; i++) {
        if (PRIV(reactor)->map[i]) {
            if (reactor->on_shutdown)
                reactor->on_shutdown(reactor, i);
            reactor_close(reactor, i);
        }
    }
    reactor_destroy(reactor);
  
}
Example #3
0
int main(int argc, char const *argv[]){
	reactor_init_with_signal(&r, NULL);

	event_set(&e, SIGINT, E_SIGNAL, sigint_callback, &r);
	reactor_add_event(&r, &e);

	pthread_t thread_id;
	pthread_create(&thread_id, NULL, thread_func, NULL);

	reactor_loop(&r, NULL, 0);

	reactor_destroy(&r);

	return 0;
}
Example #4
0
int reactor_init(struct Reactor *reactor)
{
    if (reactor->maxfd <= 0) return -1;
    reactor->priv = calloc(1, sizeof(struct reactor_private));
    PRIV(reactor)->reactor_fd = epoll_create1(0);
    PRIV(reactor)->map = calloc(1, reactor->maxfd + 1);
    PRIV(reactor)->events = calloc(sizeof(struct epoll_event),
                                   REACTOR_MAX_EVENTS);
    if (!PRIV(reactor)->reactor_fd || !PRIV(reactor)->map ||
        !PRIV(reactor)->events) {
        reactor_destroy(reactor);
        return -1;
    }
    return 0;
}