/** * Create zone transfer handler. * */ xfrhandler_type* xfrhandler_create() { xfrhandler_type* xfrh = NULL; CHECKALLOC(xfrh = (xfrhandler_type*) malloc(sizeof(xfrhandler_type))); xfrh->engine = NULL; xfrh->packet = NULL; xfrh->netio = NULL; xfrh->tcp_set = NULL; xfrh->tcp_waiting_first = NULL; xfrh->udp_waiting_first = NULL; xfrh->udp_waiting_last = NULL; xfrh->udp_use_num = 0; xfrh->start_time = 0; xfrh->current_time = 0; xfrh->got_time = 0; xfrh->need_to_exit = 0; xfrh->started = 0; /* notify */ xfrh->notify_waiting_first = NULL; xfrh->notify_waiting_last = NULL; xfrh->notify_udp_num = 0; /* setup */ xfrh->netio = netio_create(); if (!xfrh->netio) { ods_log_error("[%s] unable to create xfrhandler: " "netio_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->packet = buffer_create(PACKET_BUFFER_SIZE); if (!xfrh->packet) { ods_log_error("[%s] unable to create xfrhandler: " "buffer_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->tcp_set = tcp_set_create(); if (!xfrh->tcp_set) { ods_log_error("[%s] unable to create xfrhandler: " "tcp_set_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->dnshandler.fd = -1; xfrh->dnshandler.user_data = (void*) xfrh; xfrh->dnshandler.timeout = 0; xfrh->dnshandler.event_types = NETIO_EVENT_READ; xfrh->dnshandler.event_handler = xfrhandler_handle_dns; xfrh->dnshandler.free_handler = 0; return xfrh; }
/** * Clean up engine. * */ void engine_cleanup(engine_type* engine) { size_t i = 0; if (!engine) { return; } if (engine->workers && engine->config) { for (i=0; i < (size_t) engine->config->num_worker_threads; i++) { worker_cleanup(engine->workers[i]); } free(engine->workers); } if (engine->drudgers && engine->config) { for (i=0; i < (size_t) engine->config->num_signer_threads; i++) { worker_cleanup(engine->drudgers[i]); } free(engine->drudgers); } zonelist_cleanup(engine->zonelist); schedule_cleanup(engine->taskq); fifoq_cleanup(engine->signq); cmdhandler_cleanup(engine->cmdhandler); dnshandler_cleanup(engine->dnshandler); xfrhandler_cleanup(engine->xfrhandler); engine_config_cleanup(engine->config); lock_basic_destroy(&engine->signal_lock); lock_basic_off(&engine->signal_cond); free(engine); }
/** * Clean up engine. * */ void engine_cleanup(engine_type* engine) { size_t i = 0; allocator_type* allocator; cond_basic_type signal_cond; lock_basic_type signal_lock; if (!engine) { return; } allocator = engine->allocator; signal_cond = engine->signal_cond; signal_lock = engine->signal_lock; if (engine->workers && engine->config) { for (i=0; i < (size_t) engine->config->num_worker_threads; i++) { worker_cleanup(engine->workers[i]); } allocator_deallocate(allocator, (void*) engine->workers); } if (engine->drudgers && engine->config) { for (i=0; i < (size_t) engine->config->num_signer_threads; i++) { worker_cleanup(engine->drudgers[i]); } allocator_deallocate(allocator, (void*) engine->drudgers); } zonelist_cleanup(engine->zonelist); schedule_cleanup(engine->taskq); fifoq_cleanup(engine->signq); cmdhandler_cleanup(engine->cmdhandler); dnshandler_cleanup(engine->dnshandler); xfrhandler_cleanup(engine->xfrhandler); engine_config_cleanup(engine->config); allocator_deallocate(allocator, (void*) engine); lock_basic_destroy(&signal_lock); lock_basic_off(&signal_cond); allocator_cleanup(allocator); return; }