Пример #1
0
static pipeline_t va_pipe_pipeline(pipeline_t result_so_far,
                                   va_list args)
{
    pipe_processor_t proc = va_arg(args, pipe_processor_t);

    if(proc == NULL)
        return result_so_far;

    void*  aux       = va_arg(args, void*);
    size_t pipe_size = va_arg(args, size_t);

    if(pipe_size == 0)
    {
        pipe_consumer_free(result_so_far.out);
        result_so_far.out = NULL;
        return result_so_far;
    }

    pipe_t* pipe = pipe_new(pipe_size, 0);

    pipe_connect(result_so_far.out , proc, aux, pipe_producer_new(pipe));
    result_so_far.out = pipe_consumer_new(pipe);

    pipe_free(pipe);

    return va_pipe_pipeline(result_so_far, args);
}
Пример #2
0
void close_wtp(wtp_handle_t* handle) {
    if (!handle)
	{
        errno = EINVAL;
        return;
    }

	wtp_stop_hello_thread(handle);
	if (handle->monitor_thread) pthread_cancel(handle->monitor_thread);
	if (handle->receive_thread) pthread_cancel(handle->receive_thread);
	if (handle->msg_send_producer) pipe_producer_free(handle->msg_send_producer);
	if (handle->msg_send_consumer) pipe_consumer_free(handle->msg_send_consumer);
	if (handle->msg_recv_producer) pipe_producer_free(handle->msg_recv_producer);
	if (handle->msg_recv_consumer) pipe_consumer_free(handle->msg_recv_consumer);
	if (handle->send_thread) pthread_cancel(handle->send_thread);
	if (handle->process_thread) pthread_cancel(handle->process_thread);
	if (handle->udp_socket) close(handle->udp_socket);
	if (handle->wtp_sta_hashmap) hashmapDelete(handle->wtp_sta_hashmap);

	free(handle);
}
Пример #3
0
static void* process_pipe(void* param)
{
    connect_data_t p = *(connect_data_t*)param;
    free(param);

    char* buf = malloc(DEFAULT_BUFFER_SIZE * pipe_elem_size(PIPE_GENERIC(p.in)));

    size_t elems_read;

    while((elems_read = pipe_pop(p.in, buf, DEFAULT_BUFFER_SIZE)))
        p.proc(buf, elems_read, p.out, p.aux);

    p.proc(NULL, 0, NULL, p.aux);

    free(buf);

    pipe_consumer_free(p.in);
    pipe_producer_free(p.out);

    return NULL;
}
Пример #4
0
void *
__dt_worker(void *arg) {
	verbose(VERB_OPS, "dnstap: starting dt_worker thread");

	dt_env_t *env = (dt_env_t *) arg;
	struct sockaddr_in so_service;

	so_service.sin_family = AF_INET;
	so_service.sin_port = htons(5354);
	so_service.sin_addr.s_addr = inet_addr("127.0.0.1");
	memset(so_service.sin_zero, 0, sizeof so_service.sin_zero);

	if(!__dt_so_connect(env, so_service)) return NULL;

	// Pop events off of the queue
	dt_message_t * event;

	while(pipe_pop(env->so_consumer, &event, 1)) {
		if(send(env->so_socket, event, dt_message_size(event), 0) < 0) {
			verbose(VERB_OPS, "dnstap: error sending message: %s. Trying to reconnect", strerror(errno));

			// Requeue the event for later
			pipe_push(env->so_producer, &event, 1);

			// And try to reconnect
			close(env->so_socket);
			if(!__dt_so_connect(env, so_service)) return NULL;
		} else {
			verbose(VERB_OPS, "dnstap: sent event to dt_service");
			dt_message_free(event);
		}
	}

	verbose(VERB_OPS, "dnstap: stopping dt_worker thread");
	close(env->so_socket);
	pipe_consumer_free(env->so_consumer);
}