]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
compilation fixes
authorMartin Molnar <molnam1@fel.cvut.cz>
Wed, 11 Jun 2008 23:07:23 +0000 (01:07 +0200)
committerMartin Molnar <molnam1@fel.cvut.cz>
Wed, 11 Jun 2008 23:07:23 +0000 (01:07 +0200)
fwp/lib/core/fwp_endpoint.c
fwp/lib/core/fwp_vres.c

index 985b642de9d624cf203527426b34bfe661ca49e1..88db9758d1cbdbb11d4e7998f56d32ff28a34994 100644 (file)
@@ -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);
 }
 
index b363ad999a06836f005c899a3574113f55836afe..cf8f8eecdf2a0318e5e4d9c481a2c5017ca42f67 100644 (file)
@@ -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);