static ya_result config_zone_section_init(config_data *config) { ya_result return_code; tmp_zone_idx++; /* store the previously configured zone, if any */ config_zone_section_register(config); /* make a new zone section ready */ tmp_zones = zone_alloc(); if(FAIL(return_code = confs_init(zone_tab, tmp_zones))) { zone_free(tmp_zones); tmp_zones = NULL; osformatln(termerr, "config: zone: configuration initialize (zone): %r", return_code); } return return_code; }
struct buffer *alloc_buffer( zone_t zone, function_t function, size_t bytes ) { size_t allocSize = sizeof(struct buffer) + bytes; struct buffer *out = (struct buffer *)zone_alloc( zone, allocSize ); // we probably should distinguish between fixed- and variable-size buffers; // fixed-size buffers don't need to store their byte count here out->size = bytes; out->function = function; return out; }
void process_loop(module_hd_t *module_head) { int32_t status, tag_id; uint64_t pkt_num = 0; extern int system_exit; module_info_t *recv; packet_t *packet; if (g_conf.mode == MODE_LIVE || g_conf.mode == MODE_FILE) { /*收包,线程中加入处理*/ status = 0; packet_zone = zone_init("pcap_read", sizeof(packet_t) + MAX_PACKET_LEN, MAX_PACKET_HANDLE); assert(packet_zone); recv = module_info_get_from_name(module_head, "recv"); assert(recv && recv->ops->process); do { do { packet = (void *)zone_alloc(packet_zone, 0); } while(packet == NULL); tag_id = recv->ops->process(recv, packet); if (tag_id > 0) { assert(packet->data); pkt_num++; status = threadpool_add_task(tp, worker_thread_process, packet, 0); if (status != 0) { log_error(syslog_p, "Threadpool add task, status %d\n", status); status = 0; } if (g_conf.pkt_num != 0 && pkt_num >= g_conf.pkt_num) { system_exit = 1; } } else { status = tag_id; zone_free(packet_zone, packet); } } while( status >= 0 && !system_exit); if (g_conf.mode == MODE_FILE) { sleep(1);/*等待最后加入的work处理完成*/ } } else if (g_conf.mode == MODE_SE) { do { status = module_list_process(module_head, pktag_hd_p, -1, NULL); pkt_num++; if (g_conf.pkt_num != 0 && pkt_num >= g_conf.pkt_num) { system_exit = 1; } } while (status >= 0 && !system_exit); } }
struct buffer *clone_buffer( zone_t zone, function_t function, size_t bytes, const void *data ) { size_t allocSize = sizeof(struct buffer) + bytes; struct buffer *out = (struct buffer*)zone_alloc( zone, allocSize ); memcpy( out->bytes, data, bytes ); out->size = bytes; out->function = function; return out; }
static ya_result config_section_zone_start(struct config_section_descriptor_s *csd) { if(csd->base != NULL) { return ERROR; } zone_desc_s *zone_desc = zone_alloc(); csd->base = zone_desc; #if CONFIG_SETTINGS_DEBUG formatln("config: section: zone: start"); #endif return SUCCESS; }