From 99b4f4d6d6f18321489bae50f1762b29165f7de1 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Tue, 14 Mar 2023 12:50:27 +0100 Subject: irmd: Use buffer_t for piggybacked data Instead of passing a const void * and len, it now passes buffer_t to operations that send piggybacked data (flow_req_arr and flow_reply) and a buffer_t * for operations that send and receive piggybacked data (flow_alloc and flow_accept). Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/irmd/irm_flow.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/irmd/irm_flow.c') diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index 44d3fb7e..6d22cbc8 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -33,9 +33,10 @@ #include "irm_flow.h" -#include -#include #include +#include +#include +#include struct irm_flow * irm_flow_create(pid_t n_pid, pid_t n_1_pid, @@ -43,10 +44,14 @@ struct irm_flow * irm_flow_create(pid_t n_pid, qosspec_t qs) { pthread_condattr_t cattr; - struct irm_flow * f = malloc(sizeof(*f)); + struct irm_flow * f; + + f = malloc(sizeof(*f)); if (f == NULL) goto fail_malloc; + memset(f, 0, sizeof(*f)); + if (pthread_condattr_init(&cattr)) goto fail_cattr; @@ -59,14 +64,6 @@ struct irm_flow * irm_flow_create(pid_t n_pid, if (pthread_mutex_init(&f->state_lock, NULL)) goto fail_mutex; - f->n_pid = n_pid; - f->n_1_pid = n_1_pid; - f->flow_id = flow_id; - f->mpl = 0; - f->qs = qs; - f->data = NULL; - f->len = 0; - f->n_rb = shm_rbuff_create(n_pid, flow_id); if (f->n_rb == NULL) { log_err("Could not create ringbuffer for process %d.", n_pid); @@ -79,11 +76,16 @@ struct irm_flow * irm_flow_create(pid_t n_pid, goto fail_n_1_rbuff; } - f->state = FLOW_ALLOC_PENDING; - if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0) log_warn("Failed to set timestamp."); + f->n_pid = n_pid; + f->n_1_pid = n_1_pid; + f->flow_id = flow_id; + f->qs = qs; + + f->state = FLOW_ALLOC_PENDING; + pthread_condattr_destroy(&cattr); return f; @@ -123,7 +125,7 @@ void irm_flow_destroy(struct irm_flow * f) pthread_mutex_lock(&f->state_lock); - assert(f->len == 0); + assert(f->data.len == 0); if (f->state == FLOW_DESTROY) { pthread_mutex_unlock(&f->state_lock); -- cgit v1.2.3