Exemplo n.º 1
0
struct dt_env *
dt_create(const char *socket_path, unsigned num_workers)
{
	fstrm_res res;
	struct dt_env *env;
	struct fstrm_iothr_options *fopt;
	struct fstrm_unix_writer_options *fuwopt;
	struct fstrm_writer *fw;
	struct fstrm_writer_options *fwopt;

	verbose(VERB_OPS, "attempting to connect to dnstap socket %s",
		socket_path);
	log_assert(socket_path != NULL);
	log_assert(num_workers > 0);

	env = (struct dt_env *) calloc(1, sizeof(struct dt_env));
	if (!env)
		return NULL;

	fwopt = fstrm_writer_options_init();
	res = fstrm_writer_options_add_content_type(fwopt,
		DNSTAP_CONTENT_TYPE, sizeof(DNSTAP_CONTENT_TYPE) - 1);
	log_assert(res == fstrm_res_success);

	fuwopt = fstrm_unix_writer_options_init();
	fstrm_unix_writer_options_set_socket_path(fuwopt, socket_path);

	fw = fstrm_unix_writer_init(fuwopt, fwopt);
	log_assert(fw != NULL);

	fopt = fstrm_iothr_options_init();
	fstrm_iothr_options_set_num_input_queues(fopt, num_workers);
	env->iothr = fstrm_iothr_init(fopt, &fw);
	if (env->iothr == NULL) {
		verbose(VERB_DETAIL, "dt_create: fstrm_iothr_init() failed");
		fstrm_writer_destroy(&fw);
		free(env);
		env = NULL;
	}
	fstrm_iothr_options_destroy(&fopt);
	fstrm_unix_writer_options_destroy(&fuwopt);
	fstrm_writer_options_destroy(&fwopt);

	return env;
}
Exemplo n.º 2
0
struct dt_env *
dt_create(const char *socket_path, unsigned num_workers)
{
	char *fio_err;
	struct dt_env *env;
	struct fstrm_io_options *fopt;
	struct fstrm_unix_writer_options *fuwopt;

	verbose(VERB_OPS, "opening dnstap socket %s", socket_path);
	log_assert(socket_path != NULL);
	log_assert(num_workers > 0);

	env = (struct dt_env *) calloc(1, sizeof(struct dt_env));
	if (!env)
		return NULL;

	fuwopt = fstrm_unix_writer_options_init();
	fstrm_unix_writer_options_set_socket_path(fuwopt, socket_path);
	fopt = fstrm_io_options_init();
	fstrm_io_options_set_content_type(fopt,
					  DNSTAP_CONTENT_TYPE,
					  sizeof(DNSTAP_CONTENT_TYPE) - 1);
	fstrm_io_options_set_num_queues(fopt, num_workers);
	fstrm_io_options_set_writer(fopt, fstrm_unix_writer, fuwopt);
	env->fio = fstrm_io_init(fopt, &fio_err);
	if (env->fio == NULL) {
		verbose(VERB_DETAIL, "dt_create: fstrm_io_init() failed: %s",
			fio_err);
		free(fio_err);
		free(env);
		env = NULL;
	}
	fstrm_io_options_destroy(&fopt);
	fstrm_unix_writer_options_destroy(&fuwopt);

	return env;
}