static int init_mysql_module() { ctx.pool = tc_create_pool(TC_PLUGIN_POOL_SIZE, TC_PLUGIN_POOL_SUB_SIZE, 0); if (ctx.pool) { ctx.table = hash_create(ctx.pool, 65536); if (ctx.table) { return TC_OK; } } return TC_ERR; }
void delay_table_add(uint64_t key, struct msg_server_s *msg) { tc_pool_t *pool; p_link_node ln; delay_sess_t *s; struct msg_server_s *cmsg; s = (delay_sess_t *) hash_find(table, key); if (s == NULL) { pool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0); if (pool != NULL) { s = (delay_sess_t *) tc_pcalloc(pool, sizeof(delay_sess_t)); if (s != NULL) { s->key = key; s->pool = pool; s->msg_list = link_list_create(s->pool); s->evt = tc_event_add_timer(s->pool, OUTPUT_INTERVAL, s, tc_delay_del_obs); msg_ls_cnt++; hash_add(table, s->pool, key, s); } else { return; } } else { return; } } cmsg = copy_message(s->pool, msg); if (cmsg != NULL) { ln = link_node_malloc(s->pool, (void *) cmsg); link_list_append(s->msg_list, ln); msg_item_cnt++; } }
int tc_event_loop_init(tc_event_loop_t *loop, int size) { tc_pool_t *pool; tc_event_actions_t *actions; pool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0); if (pool != NULL) { actions = &tc_event_actions; loop->actions = actions; loop->active_events = NULL; loop->pool = pool; loop->size = size; if (actions->create(loop) == TC_EVENT_ERROR) { return TC_EVENT_ERROR; } return TC_EVENT_OK; } else { return TC_EVENT_ERROR; } }
/* * main entry point */ int main(int argc, char **argv) { int ret, is_continue = 1; settings_init(); #if (TC_SIGACTION) if (set_signal_handler(signals) == -1) { return -1; } #else signal(SIGINT, tcp_copy_over); //signal(SIGPIPE, tcp_copy_over); //signal(SIGHUP, tcp_copy_over); signal(SIGTERM, tcp_copy_over); #endif tc_time_init(); if (read_args(argc, argv) == -1) { return -1; } if (tc_log_init(clt_settings.log_path) == -1) { return -1; } clt_settings.pool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0, 0); if (clt_settings.pool == NULL) { return -1; } /* output debug info */ output_for_debug(); /* set details for running */ if (set_details() == -1) { return -1; } #if (TC_DIGEST) tc_init_digests(); if (!tc_init_sha1()) { return -1; } #endif #if (MINGW32) WSADATA wsadata; if(WSAStartup(MAKEWORD(2,2),&wsadata)==SOCKET_ERROR) { tc_log_info(LOG_ERR, 0, "WSAStartup failed"); return -1; } #endif tc_event_timer_init(); ret = tc_event_loop_init(&event_loop, MAX_FD_NUM); if (ret == TC_EVENT_ERROR) { tc_log_info(LOG_ERR, 0, "event loop init failed"); is_continue = 0; } if (is_continue) { ret = tcp_copy_init(&event_loop); if (ret == TC_ERR) { is_continue = 0; } } if (is_continue) { /* run now */ tc_log_info(LOG_NOTICE, 0, "starting event handling loop...."); tc_event_proc_cycle(&event_loop); } tcp_copy_release_resources(); #if (MINGW32) tc_log_info(LOG_INFO, 0, "WSACleanup"); WSACleanup(); #endif return 0; }
int main(int argc, char **argv) { int ret; settings_init(); if (set_signal_handler(signals) == -1) { return -1; } tc_time_init(); if (read_args(argc, argv) == -1) { return -1; } if (tc_log_init(srv_settings.log_path) == -1) { return -1; } srv_settings.pool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0); if (srv_settings.pool == NULL) { return -1; } srv_settings.cpool = tc_create_pool(TC_DEFAULT_POOL_SIZE, 0); if (srv_settings.cpool == NULL) { tc_destroy_pool(srv_settings.pool); return -1; } ret = tc_event_loop_init(&s_evt_loop, MAX_FD_NUM); if (ret == TC_EVENT_ERROR) { tc_log_info(LOG_ERR, 0, "event loop init failed"); return -1; } /* output debug info */ output_for_debug(); if (set_details() == -1) { return -1; } tc_event_timer_init(); if (server_init(&s_evt_loop, srv_settings.bound_ip, srv_settings.port) == TC_ERR) { return -1; } #if (TC_COMBINED) tc_event_add_timer(s_evt_loop.pool, CHECK_INTERVAL, NULL, server_push); #endif tc_event_add_timer(s_evt_loop.pool, OUTPUT_INTERVAL, NULL, server_stat); /* run now */ tc_event_proc_cycle(&s_evt_loop); server_release_resources(); return 0; }