+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
+/* */
+/* Universidad de Cantabria, SPAIN */
+/* University of York, UK */
+/* Scuola Superiore Sant'Anna, ITALY */
+/* Kaiserslautern University, GERMANY */
+/* Univ. Politécnica Valencia, SPAIN */
+/* Czech Technical University in Prague, CZECH REPUBLIC */
+/* ENEA SWEDEN */
+/* Thales Communication S.A. FRANCE */
+/* Visual Tools S.A. SPAIN */
+/* Rapita Systems Ltd UK */
+/* Evidence ITALY */
+/* */
+/* See http://www.frescor.org for a link to partners' websites */
+/* */
+/* FRESCOR project (FP6/2005/IST/5-034026) is funded */
+/* in part by the European Union Sixth Framework Programme */
+/* The European Union is not liable of any use that may be */
+/* made of this code. */
+/* */
+/* */
+/* This file is part of FWP (Frescor WLAN Protocol) */
+/* */
+/* FWP is free software; you can redistribute it and/or modify it */
+/* under terms of the GNU General Public License as published by the */
+/* Free Software Foundation; either version 2, or (at your option) any */
+/* later version. FWP is distributed in the hope that it will be */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* General Public License for more details. You should have received a */
+/* copy of the GNU General Public License along with FWP; see file */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
+/* Cambridge, MA 02139, USA. */
+/* */
+/* As a special exception, including FWP header files in a file, */
+/* instantiating FWP generics or templates, or linking other files */
+/* with FWP objects to produce an executable application, does not */
+/* by itself cause the resulting executable application to be covered */
+/* by the GNU General Public License. This exception does not */
+/* however invalidate any other reasons why the executable file might be */
+/* covered by the GNU Public License. */
+/**************************************************************************/
#include "fwp_utils.h"
#include "fwp_vres.h"
/* consideration: move tx_queue to endpoint */
/**< queue for messages to send */
struct fwp_msgq tx_queue;
- int flags;
+ fwp_vres_flag_t flags;
/**< endpoint bounded to this vres */
/*fwp_endpoint_t *epoint; */
pthread_t tx_thread; /**< tx_thread id*/
pthread_attr_t tx_thread_attr;
int ac_sockd; /**< ac socket descriptor */
- fwp_sockaddr_t addr; /**< dest addr,for effectivness*/
};
typedef
/*inline int fwp_vres_get(fwp_vres_id_t vres_id, fwp_vres_t **vres )
{
- 3if ((vres_id < 0) || (vres_id > fwp_vres_table.nr_vres - 1))
+ if ((vres_id < 0) || (vres_id > fwp_vres_table.nr_vres - 1))
return -EINVAL;
*vres = &fwp_vres_table.entry[vres_id];
return 0;
fwp_budget_t budget = vres->params.budget;
fwp_budget_t curr_budget;
int rc;
-
- struct timespec start_period, end_period, period;
- struct timespec current_time, interval;
+ struct timespec start_period, period, interval, current_time;
fwp_set_rt_prio(90 - ac_id);
-
-
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_cleanup_push(fwp_vres_cleanup, (void*)vres);
+ /* just for sure */
+ fwp_vres_sched_update(vres, &period, &budget);
clock_gettime(CLOCK_MONOTONIC, &start_period);
+ curr_budget = 0;
while (1) {
/* wait for next period and then send */
- fwp_timespec_add(&end_period, &start_period, &period);
- clock_gettime(CLOCK_MONOTONIC, ¤t_time);
+ /*clock_gettime(CLOCK_MONOTONIC, ¤t_time);
fwp_timespec_sub(&interval, &end_period, ¤t_time);
- nanosleep(&interval, NULL);
+ nanosleep(&interval, NULL);*/
- sem_wait(&msgq->empty_lock);
- fwp_vres_sched_update(vres, &period, &budget);
- clock_gettime(CLOCK_MONOTONIC, &start_period);
+ /*while((rc = sem_wait(&msgq->empty_lock, &end_period))==-1
+ && errno == EINTR) {
+ continue;
+ }*/
- /*msgb = fwp_msgq_dequeue(msgq);
- *if (msgb){*/
- curr_budget = 0;
- while ((curr_budget < budget)&&
- (msgb = fwp_msgq_dequeue(msgq))) {
- rc = _fwp_vres_send(vres->ac_sockd, msgb);
- if (!(rc < 0)) {
- FWP_DEBUG("Message sent through AC%d\n",ac_id);
- /* Switch to this in the future
- * curr_budget+= msgb->len;
- */
- curr_budget++;
- }
-
- fwp_msgb_free(msgb);
+ msgb = fwp_msgq_dequeue(msgq);
+ fwp_vres_sched_update(vres, &period, &budget);
+ if ((curr_budget + msgb->len) > budget) {
+ /* need to recharge */
+ clock_gettime(CLOCK_MONOTONIC, ¤t_time);
+ fwp_timespec_sub(&interval, ¤t_time, &start_period);
+ fwp_timespec_modulo(&interval, &interval, &period);
+ fwp_timespec_sub(&interval, &period, &interval);
+ nanosleep(&interval, NULL);
+ curr_budget = 0;
+ clock_gettime(CLOCK_MONOTONIC, &start_period);
}
+ rc = _fwp_vres_send(vres->ac_sockd, msgb);
+ if (!(rc < 0)) {
+ FWP_DEBUG("Message sent through AC%d\n",ac_id);
+ curr_budget+= msgb->len;
+ } else {
+ FWP_DEBUG("Message sent error %d\n",rc);
+ }
+
+ fwp_msgb_free(msgb);
+
/*pthread_testcancel(); */
/*pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);