tb_void_t tb_lo_scheduler_io_exit(tb_lo_scheduler_io_ref_t scheduler_io) { // check tb_assert_and_check_return(scheduler_io); // exit poller if (scheduler_io->poller) tb_poller_exit(scheduler_io->poller); scheduler_io->poller = tb_null; #ifndef TB_CONFIG_MICRO_ENABLE // exit timer if (scheduler_io->timer) tb_timer_exit(scheduler_io->timer); scheduler_io->timer = tb_null; // exit ltimer if (scheduler_io->ltimer) tb_ltimer_exit(scheduler_io->ltimer); scheduler_io->ltimer = tb_null; #endif // clear scheduler scheduler_io->scheduler = tb_null; // exit it tb_free(scheduler_io); }
/* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ tb_poller_ref_t tb_poller_init(tb_cpointer_t priv) { // done tb_bool_t ok = tb_false; tb_poller_poll_ref_t poller = tb_null; do { // make poller poller = tb_malloc0_type(tb_poller_poll_t); tb_assert_and_check_break(poller); // init poll fds poller->pfds = tb_vector_init(0, tb_element_mem(sizeof(struct pollfd), tb_null, tb_null)); tb_assert_and_check_break(poller->pfds); // init copied poll fds poller->cfds = tb_vector_init(0, tb_element_mem(sizeof(struct pollfd), tb_null, tb_null)); tb_assert_and_check_break(poller->cfds); // init user private data poller->priv = priv; // init pair sockets if (!tb_socket_pair(TB_SOCKET_TYPE_TCP, poller->pair)) break; // insert pair socket first if (!tb_poller_insert((tb_poller_ref_t)poller, poller->pair[1], TB_POLLER_EVENT_RECV, tb_null)) break; // ok ok = tb_true; } while (0); // failed? if (!ok) { // exit it if (poller) tb_poller_exit((tb_poller_ref_t)poller); poller = tb_null; } // ok? return (tb_poller_ref_t)poller; }