From 8c846c624b6470a514e1b5b6f7dffe8f73a207c3 Mon Sep 17 00:00:00 2001 From: Martin Molnar Date: Thu, 12 Jun 2008 01:07:23 +0200 Subject: [PATCH] compilation fixes --- fwp/lib/core/fwp_endpoint.c | 10 +++++++ fwp/lib/core/fwp_vres.c | 58 +++++++++++++++---------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/fwp/lib/core/fwp_endpoint.c b/fwp/lib/core/fwp_endpoint.c index 985b642..88db975 100644 --- a/fwp/lib/core/fwp_endpoint.c +++ b/fwp/lib/core/fwp_endpoint.c @@ -171,6 +171,15 @@ int fwp_send_endpoint_create(unsigned int node, unsigned int port, goto err; } + /* Enable broadcasts */ + unsigned int yes = 1; + if (setsockopt(sockd,SOL_SOCKET, SO_BROADCAST/*SO_REUSEADDR*/, &yes, + sizeof(yes)) == -1) { + perror("Unable to set BROADCAST option for socket"); + close(sockd); + return (-errno); + } + if (connect(sockd,(struct sockaddr*) &epoint->peer.addr, epoint->peer.addrlen)) { perror("Connect error"); @@ -437,6 +446,7 @@ int fwp_send(fwp_endpoint_d_t epointd, void *msg, size_t size, int flags) /*}*/ + /* TODO: test whether _fwp_vres_send is successful */ return _fwp_vres_send(epoint->vresd, msgb); } diff --git a/fwp/lib/core/fwp_vres.c b/fwp/lib/core/fwp_vres.c index b363ad9..cf8f8ee 100644 --- a/fwp/lib/core/fwp_vres.c +++ b/fwp/lib/core/fwp_vres.c @@ -23,7 +23,7 @@ struct fwp_vres{ struct fwp_msgq tx_queue; int flags; /**< endpoint bounded to this vres */ - fwp_endpoint_d_t epointd; + fwp_endpoint_t *epoint; pthread_t tx_thread; /**< tx_thread id*/ pthread_attr_t tx_thread_attr; int ac_sockd; /**< ac socket descriptor */ @@ -47,6 +47,20 @@ static fwp_vres_table_t fwp_vres_table = { static const int prio_to_ac[8] = {2,3,3,2,1,1,0,0}; static const unsigned int ac_to_tos[4] = {224,160,96,64}; +static inline int fwp_vres_set_ac(int sockd, fwp_ac_t ac_id) +{ + unsigned int tos; + + tos = ac_to_tos[ac_id]; + if (setsockopt(sockd, SOL_IP, IP_TOS, &tos, sizeof(tos)) == -1) { + perror("Root permission needed to set AC"); + return (-errno); + } + + return 0; +} + +/* Deprecated */ static int fwp_vres_ac_open(fwp_ac_t ac_id) { int sockd; @@ -59,14 +73,6 @@ static int fwp_vres_ac_open(fwp_ac_t ac_id) perror("Unable to open socket for AC"); return (-errno); } - - unsigned int yes = 1; - if (setsockopt(sockd,SOL_SOCKET, SO_BROADCAST/*SO_REUSEADDR*/, &yes, - sizeof(yes)) == -1) { - perror("Unable to set options for socket"); - close(sockd); - return (-errno); - } tos = ac_to_tos[ac_id]; @@ -169,18 +175,15 @@ int fwp_vres_set_params(fwp_vres_d_t vresd, fwp_vres_params_t *params) * state - restart thread, set vres_resched flag */ pthread_cancel(vres->tx_thread); - close(vres->ac_sockd); /* or set vres_resched flag and return */ } else{ /* initialize msg queue */ fwp_msgq_init(&vres->tx_queue); } - /* open ac socket */ - if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) { + if ((rv = fwp_vres_set_ac(vres->ac_sockd, vres->params.ac_id)) < 0) { goto err; } - vres->ac_sockd = rv; pthread_attr_init(&vres->tx_thread_attr); if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr, @@ -211,12 +214,7 @@ int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp) memcpy(&vres->params, params, sizeof(struct fwp_vres_params)); /* initialize msg queue */ fwp_msgq_init(&vres->tx_queue); - /* open ac socket */ - if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) { - goto err; - } - vres->ac_sockd = rv; - + pthread_attr_init(&vres->tx_thread_attr); if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr, fwp_vres_tx_thread, (void*) vres)) != 0){ @@ -225,7 +223,6 @@ int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp) } vres->status = FWP_VRES_UNBOUND; -/* return vres->params.id; */ *vresdp = vres; return 0; err: @@ -242,12 +239,7 @@ int fwp_vres_destroy(fwp_vres_d_t vresd) return -EPERM; vres->status = FWP_VRES_INACTIVE; - - /* unbind endpoint */ - fwp_send_endpoint_unbind(vres->epointd); - pthread_cancel(vres->tx_thread); - close(vres->ac_sockd); FWP_DEBUG("Vres vparam_id=%d destroyed.\n", vres->params.id); return 0; @@ -267,7 +259,7 @@ static void* fwp_vres_tx_thread(void *_vres) struct fwp_msgq *msgq = &vres->tx_queue; struct fwp_msgb *msgb = NULL; unsigned int ac_id = vres->params.ac_id; - unsigned int ac_sockd = vres->ac_sockd; + /*unsigned int ac_sockd = vres->ac_sockd;*/ int budget = vres->params.budget; int curr_budget; int rc; @@ -302,7 +294,7 @@ static void* fwp_vres_tx_thread(void *_vres) clock_gettime(CLOCK_MONOTONIC, &start_period); /*msgb = fwp_msgq_dequeue(msgq); - if (msgb){*/ + *if (msgb){*/ curr_budget = 0; while ((curr_budget < budget)&& (msgb = fwp_msgq_dequeue(msgq))) { @@ -338,26 +330,24 @@ int _fwp_vres_send(fwp_vres_d_t vresd, struct fwp_msgb* msgb) { fwp_vres_t *vres = vresd; - /* test flags to check whether to send reliably*/ - if (vres->status != FWP_VRES_INACTIVE) { + if (vres->status == FWP_VRES_BOUND) { return fwp_msgq_enqueue(&vres->tx_queue, msgb); } else return -EPERM; } -int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_d_t epointd, int sockd) +int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_t *epoint) { fwp_vres_t *vres = vresd; - fwp_endpoint_t *epoint = epointd; int rv = 0; pthread_mutex_lock(&fwp_vres_table.lock); if (vres->status == FWP_VRES_BOUND) /*if other endpoint is assigned to vres*/ rv = -EPERM; else { - vres->epointd = epointd; - /*TODO*/ - vres->ac_sockd = sockd; + vres->epoint = epoint; + vres->ac_sockd = epoint->sockd; + fwp_vres_set_ac(vres->ac_sockd,vres->params.ac_id); vres->status = FWP_VRES_BOUND; } pthread_mutex_unlock(&fwp_vres_table.lock); -- 2.39.2