*
* \return On success returns 0. On error, -1 and errno is set appropriately.
*/
-int fwp_send_endpoint_bind(fwp_endpoint_t *epoint, fwp_vres_d_t vresd)
+int fwp_send_endpoint_bind(fwp_vres_d_t vresd, fwp_endpoint_t *epoint)
{
int rv ;
fwp_endpoint_t *fwp_epoint = epoint;
- rv = _fwp_vres_bind(vresd, fwp_epoint->sockd);
+ rv = fwp_vres_bind(vresd, fwp_epoint->sockd);
/* if send endpoint is already bound
if (epoint->type == FWP_EPOINT_BOUND) {
fwp_send_endpoint_unbind(epoint);
fwp_endpoint_t *fwp_epoint = epointd;
/* unlink epoint-vres mutually */
- if ((rv = _fwp_vres_unbind(fwp_epoint->vresd)) < 0)
+ if ((rv = fwp_vres_unbind(fwp_epoint->vresd)) < 0)
return rv;
return 0;
/*}*/
/* TODO: test whether _fwp_vres_send is successful */
- return _fwp_vres_send(fwp_epoint->vresd, msgb);
+ return fwp_vres_send(fwp_epoint->vresd, msgb);
}
typedef enum {
FWP_VF_USED = 1 ,
- FWP_VF_ACTIVE = 2 ,
+ FWP_VF_BOUND = 2 ,
FWP_VF_RESCHED = 4 ,
} fwp_vres_flag_t;
return 0;
}
-static inline int fwp_vres_set_flag(fwp_vres_t *vres, fwp_vres_flag_t flag)
+static inline void fwp_vres_set_flag(fwp_vres_t *vres, fwp_vres_flag_t flag)
{
- return (vres->flags | (1 << flag));
+ vres->flags |= (1 << flag);
}
-static inline int fwp_vres_clear_flag(fwp_vres_t *vres, fwp_vres_flag_t flag)
+static inline void fwp_vres_clear_flag(fwp_vres_t *vres, fwp_vres_flag_t flag)
{
- return (vres->flags & ~(1 << flag));
+ vres->flags &= ~(1 << flag);
}
static inline int fwp_vres_get_flag(fwp_vres_t *vres, fwp_vres_flag_t flag)
return !!(vres->flags & (1 << flag));
}
+static inline void fwp_vres_clearall_flag(fwp_vres_t *vres)
+{
+ vres->flags = 0;
+}
+
#if 0
/* Deprecated */
static int fwp_vres_ac_open(fwp_ac_t ac_id)
}
#endif
-static inline int __fwp_vres_send(unsigned int ac_sockd, struct fwp_msgb* msgb)
+static inline int _fwp_vres_send(unsigned int ac_sockd, struct fwp_msgb* msgb)
{
/*_fwp_sendto(ac_sockd, msgb->data, msgb->len, 0,
msgb->peer->addr, msgb->peer->addrlen);*/
static inline void fwp_vres_free(fwp_vres_t *vres)
{
- fwp_vres_clear_flag(vres, FWP_VF_USED);
+ fwp_vres_clearall_flag(vres);
}
static inline int fwp_vres_is_valid(fwp_vres_t *vres)
inline int _fwp_vres_set_params(fwp_vres_t *vres, fwp_vres_params_t *params)
{
+ int rv;
+
/* copy vres paramters into vres structure */
rv = fwp_vres_set_ac(vres->ac_sockd, params->ac_id);
if (!rv)
int fwp_vres_set_params(fwp_vres_d_t vresd, fwp_vres_params_t *params)
{
fwp_vres_t *vres = vresd;
- int rv;
if (!fwp_vres_is_valid(vres)) {
errno = EINVAL;
return -1;
}
- return fwp_vres_set_params(vres, params);
+ return _fwp_vres_set_params(vres, params);
}
/**
int rv;
fwp_vres_t *vres;
- /* Check for validity of the contract */
-
vres = fwp_vres_alloc();
if (!vres) {
return -1;
}
- /* copy vres paramters into vres structure */
- memcpy(&vres->params, params, sizeof(struct fwp_vres_params));
/* initialize msg queue */
fwp_msgq_init(&vres->tx_queue);
+ _fwp_vres_set_params(vres, params);
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){
goto err;
}
- _fwp_vres_set_params
+
*vresdp = vres;
return 0;
err:
fwp_vres_free(vres);
- errno = rv;
return -1;
}
}
pthread_cancel(vres->tx_thread);
-
+
FWP_DEBUG("Vres vparam_id=%d destroyed.\n", vres->params.id);
return 0;
}
struct fwp_msgb *msgb = NULL;
unsigned int ac_id = vres->params.ac_id;
/*unsigned int ac_sockd = vres->ac_sockd;*/
- int budget = vres->params.budget;
- int curr_budget;
+ fwp_budget_t budget = vres->params.budget;
+ fwp_budget_t curr_budget;
int rc;
struct timespec start_period, end_period, period;
curr_budget = 0;
while ((curr_budget < budget)&&
(msgb = fwp_msgq_dequeue(msgq))) {
- rc = __fwp_vres_send(vres->ac_sockd, msgb);
+ 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
return NULL;
}
-int _fwp_vres_send(fwp_vres_d_t vresd, struct fwp_msgb* msgb)
+int fwp_vres_send(fwp_vres_d_t vresd, struct fwp_msgb* msgb)
{
fwp_vres_t *vres = vresd;
}
}
-#if 0
-/*int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_t *epoint)*/
-int _fwp_vres_bind(fwp_vres_d_t vresd, int sockd)
+/*int fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_t *epoint)*/
+int fwp_vres_bind(fwp_vres_d_t vresd, int sockd)
{
fwp_vres_t *vres = vresd;
int rv = 0;
goto err;
}
- if (vres->status != FWP_VRES_UNBOUND) { /*if already bounded */
+ if (fwp_vres_get_flag(vres, FWP_VF_BOUND)) { /*if already bounded */
errno = EPERM;
rv = -1;
goto err;
}
vres->ac_sockd = sockd;
- fwp_vres_set_ac(vres->ac_sockd,vres->params.ac_id);
- vres->status = FWP_VRES_BOUND;
+ rv = fwp_vres_set_ac(vres->ac_sockd,vres->params.ac_id);
+ if (rv)
+ goto err;
+ fwp_vres_set_flag(vres, FWP_VF_BOUND);
err:
pthread_mutex_unlock(&fwp_vres_table.lock);
return rv;
}
-int _fwp_vres_unbind(fwp_vres_d_t vresd)
+int fwp_vres_unbind(fwp_vres_d_t vresd)
{
fwp_vres_t *vres = vresd;
errno = EINVAL;
return -1;
}
- vres->status = FWP_VRES_UNBOUND;
+ fwp_vres_clear_flag(vres, FWP_VF_BOUND);
/* TODO: consider what to do with pending messages */
/* fwp_vres_free_msgb(vres->tx_queue); */
-
return 0;
}
-#endif