]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Merge branch 'master' of rtime:/var/git/frescor
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jan 2008 16:51:51 +0000 (17:51 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jan 2008 16:51:51 +0000 (17:51 +0100)
fwp/config.omk [new file with mode: 0644]
fwp/libfwp/include/fwp_ac.h
fwp/libfwp/src/fwp_ac.c
fwp/libfwp/src/fwp_proto.c
fwp/libfwp/src/fwp_vres.c
fwp/tests/Makefile.omk
fwp/tests/fwp_prototest/Makefile.omk
fwp/tests/fwp_prototest/fwp_sendrecv_test.c

diff --git a/fwp/config.omk b/fwp/config.omk
new file mode 100644 (file)
index 0000000..69959d4
--- /dev/null
@@ -0,0 +1 @@
+CFLAGS+= -Wall -Wextra
index e7f4843755c4086e828c8676fb75ae2df7b51909..6aad90db6c87f99ae944d6cfb10690468b315a87 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 
+#include <stdio.h>
 #include "fwp_conf.h"
 #include "fwp_msgb.h"
 
index 3d2fc826e3035a0c3ef4d60a723f6e2a226c2d10..ac5c5b862fe6c7011d1ca4dbcdf83361a6510ee7 100644 (file)
@@ -1,7 +1,6 @@
 #include "fwp_ac.h"
 #include "fwp_util.h"
 
-
 enum ac_status_t {
        FWP_AC_CLOSED = 0,
        FWP_AC_OPENED = 1
@@ -34,7 +33,7 @@ void fwp_ac_table_init()
 int fwp_ac_open(unsigned int id) 
 {
        int sockfd;
-       unsigned int yes=1, tos;
+       unsigned int tos;
        struct fwp_ac *ac = &fwp_ac_table[id];
        
        //if ((id < 0)||(id >= AC_NUM)||(ac[id].status != OPENED))
@@ -45,54 +44,60 @@ int fwp_ac_open(unsigned int id)
                return 0;
        }
 
-       if ((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
-       {
-               /*perror("Unable to open socket");*/
-               return -1;
+       if ((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+               perror("fwp_ac_open - Unable to open socket for AC");
+               return (-errno);
        }
        
-       if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
-               /*perror("Unable to set socket");*/
-               return -1;
-       }
+       /*
+        * Not needed
+        * unisgned int yes = 1;
+        * if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR, &yes, 
+        *                sizeof(int)) == -1) {
+        *      perror("fwp_ac_open - Root permission needed to set AC)");
+               close(sockfd);
+               return (-errno);
+       }*/
 
        tos = ac_to_tos[id];
-       if (setsockopt(sockfd, SOL_IP, IP_TOS, &tos, sizeof(tos))) {
-               /*perror("Unable to set TOS");*/
+#if 0
+       if (setsockopt(sockfd, SOL_IP, IP_TOS, &tos, sizeof(tos)) == -1) {
+               perror("fwp_ac_open - Root permission needed to set AC");
                close(sockfd);
-               return -1;
+               return (-errno);
        }
-
+#endif
        ac->sockfd = sockfd;
        ac->status = FWP_AC_OPENED;
        ac->count++;
-
        return 0;
 }
 
-
 int fwp_ac_close(unsigned int id) 
 {
        struct fwp_ac *ac = &fwp_ac_table[id];
        
-       if (ac->status != FWP_AC_OPENED) return -1; 
+       if (ac->status != FWP_AC_OPENED) 
+               return -EPERM; 
        if (--ac->count == 0) {
                close(ac->sockfd);
                ac->status = FWP_AC_CLOSED;
        }
+       
        return 0;
 }
 
 int fwp_ac_send(unsigned int id, struct fwp_msgb* msgb)
 {
+       if (!msgb)
+               return -EINVAL;
        while (sendto(fwp_ac_table[id].sockfd, msgb->head, msgb->len,
                      /*msgb_>flags*/0, &msgb->addr, msgb->addrlen) < 0) {
 
                if (errno == EINTR) continue;
-               /*perror("Error while sending data");*/
-               return -1;
+               perror("fwp_ac_send - Error while sending data");
+               return (-errno);
        }
        
        return 0;
 }
-
index 8b2f8bac760750f58fee035e200efb73864a70be..b8e20aef2187e4f00ba88843187d4afcd7cd95a5 100644 (file)
@@ -16,7 +16,8 @@ int fwp_init()
 {
        fwp_vres_table_init();
        fwp_ac_table_init();
-
+       
+#if 0
        /* Open socket to fwp agent */
 
 #warning Asi to bude chtit pouzit SOCK_DGRAM nebo SOCK_SEQPACKET, abychom nemuseli hledat zacatky paketu.      
@@ -27,6 +28,7 @@ int fwp_init()
        strcpy(fwp_agent_addr.sun_path, "manager_socket");
 
 #warning Chybi volani bind() a v pripade SOCK_STREAM connect() 
+#endif
        return 0;
 }
 
index ce1ef1e45da2297bfe7de000e779d964abb6164d..f7b97d61cafe93da4ba3c901d5aced3c244a9942 100644 (file)
@@ -12,8 +12,8 @@
 static void* fwp_vres_tx_thread(void *_vres);
 
 enum fwp_vres_status_t {
-       CLOSED = 0 ,
-       OPENED = 1 ,
+       FWP_VRES_CLOSED = 0 ,
+       FWP_VRES_OPENED = 1 ,
 };
 
 /**
@@ -26,7 +26,7 @@ struct fwp_vres{
        struct fwp_msgq tx_queue;
        pthread_t tx_thread;
        pthread_attr_t tx_thread_attr;
-       unsigned int status;
+       int status;
 };
 
 struct fwp_vres fwp_vres_table[FWP_VRES_MAX];
@@ -36,13 +36,13 @@ void fwp_vres_table_init()
        int id;
 
        for (id = 0; id < FWP_VRES_MAX; id++) 
-               fwp_vres_table[id].status = CLOSED;
+               fwp_vres_table[id].status = FWP_VRES_CLOSED;
 }
 
 int fwp_vres_open(struct fwp_contract *cnt)
 /* queueing policy should be next parameter*/
 {
-       int id;
+       int id,rc;
        struct fwp_vres *vres;
        
        /* Check for validity of the contract */
@@ -50,38 +50,41 @@ int fwp_vres_open(struct fwp_contract *cnt)
        /* obtain fwp_vres_table mutex */
        /* find free vres */
        id = 0;
-       while ((id < FWP_VRES_MAX) && (fwp_vres_table[id].status != CLOSED)) 
+       while ((id < FWP_VRES_MAX) && 
+               (fwp_vres_table[id].status != FWP_VRES_CLOSED)){ 
+               
                id++;
+       }
        if (id == FWP_VRES_MAX) {
                /* release fwp_vres_table mutex */
                return -1;
        }
        
+       fprintf(stderr,"id= %d\n",id);
        vres = &fwp_vres_table[id];
-       vres->status = OPENED;
+       vres->status = FWP_VRES_OPENED;
        /* release fwp_vres_table mutex */
 
        memcpy(&vres->contract, cnt, sizeof(struct fwp_contract));      
 
        fwp_msgq_init(&vres->tx_queue);
-               
-       if (fwp_ac_open(vres->contract.ac_id) < 0)
+       if ((rc = fwp_ac_open(vres->contract.ac_id)) < 0) {
                return -1; 
-
+       }
+       printf("rc = %d \n", rc);
        pthread_attr_init(&vres->tx_thread_attr);
-       return 0;
-//     return pthread_create(&vres->tx_thread, &vres->tx_thread_attr, 
-//                         fwp_vres_tx_thread, (void*) vres);
+       return pthread_create(&vres->tx_thread, &vres->tx_thread_attr, 
+                           fwp_vres_tx_thread, (void*) vres);
 }
 
 int fwp_vres_close(unsigned int id)
 {      
        struct fwp_vres *vres = &fwp_vres_table[id];
 
-       //if ((id < 0)||(id >= MAX_FWP_VRES)||(vres->status != OPENED))
+       //if ((id < 0)||(id >= MAX_FWP_VRES)||(vres->status != FWP_VRES_OPENED))
        //      return -1;
                 
-       vres->status = CLOSED;
+       vres->status = FWP_VRES_CLOSED;
        if (fwp_ac_close(vres->contract.ac_id) < 0)
                return -1;
        
index 032087bdcc8b6640638c0a5b126778bfe1c9b4ff..ecf3bc8a1f44b000f06933b9eca9c6f81033d839 100644 (file)
@@ -1 +1,2 @@
-SUBDIRS= fwp_msgtest fwp_prototest unixsocktest
+#SUBDIRS= fwp_msgtest fwp_prototest unixsocktest
+SUBDIRS= fwp_prototest
index 0aa0a9ba56f171fbe557fbaccb61c15093d523c5..e82b76962a81a2af638f164c9ab6cb01462bc35f 100644 (file)
@@ -1,3 +1,4 @@
+#CFLAGS+= -Wall -Wextra
 test_PROGRAMS = fwp_sendrecv_test
 fwp_sendrecv_test_SOURCES+= fwp_sendrecv_test.c
 lib_LOADLIBES += fwp pthread rt 
index c6b33992ccf5f668eb518415a84f7890b8f9782b..208d5974a0304c0d2fc02e939616388287569c6b 100644 (file)
@@ -7,18 +7,18 @@
 
 int main()
 {
-       struct sockaddr_in local_addr, rem_addr, from;
-       int sockfd;
-        long len;
-       unsigned int vres_id1, vres_id2;
-       int i;
+       //struct sockaddr_in local_addr, rem_addr, from;
+       //int sockfd;
+        //long len;
+       int vres_id1, vres_id2;
+       //int i;
        struct fwp_contract cnt1;
        struct fwp_contract cnt2;
-       char msg1[] = "Hello1";
-       char msg2[] = "Hello2";
-       char buffer[30];
-       struct fwp_msgb *msgb;
-       socklen_t fromlen;
+       //char msg1[] = "Hello1";
+       //char msg2[] = "Hello2";
+       //char buffer[30];
+       //struct fwp_msgb *msgb;
+       //socklen_t fromlen;
 
        cnt1.ac_id = FWP_AC_VO; 
        cnt1.budget = 100;
@@ -29,10 +29,20 @@ int main()
        cnt2.period_usec = 150;
 
        printf("Start\n");
-       fwp_vres_table_init();
-       vres_id1 = fwp_vres_open(&cnt1);
-       vres_id2 = fwp_vres_open(&cnt2);
-       printf("Vres created\n");
+       fwp_init();
+       
+       if ((vres_id1 = fwp_vres_open(&cnt1) < 0)) {
+               printf("fw_vres_open - Unable to open vres1\n");
+               return -1;
+       }
+       printf("Vres created vresid1= %d \n",vres_id1);
+       
+       if ((vres_id2 = fwp_vres_open(&cnt2)) < 0){
+               fprintf(stderr,"fw_vres_open - Unable to open vres2\n");
+               return -1;
+       }
+       printf("Vres created vresid2= %d \n",vres_id2);
+       
 #if 0
         memset(&local_addr,0, sizeof(local_addr));
         if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {