From: Michal Sojka Date: Fri, 18 Jan 2008 16:51:51 +0000 (+0100) Subject: Merge branch 'master' of rtime:/var/git/frescor X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fwp.git/commitdiff_plain/9e98519ca8349baaee4a992a9a13992b60388b0a?hp=a71aa50df71d90adec9278ab949e99b5c565d43f Merge branch 'master' of rtime:/var/git/frescor --- diff --git a/fwp/config.omk b/fwp/config.omk new file mode 100644 index 0000000..69959d4 --- /dev/null +++ b/fwp/config.omk @@ -0,0 +1 @@ +CFLAGS+= -Wall -Wextra diff --git a/fwp/libfwp/include/fwp_ac.h b/fwp/libfwp/include/fwp_ac.h index e7f4843..6aad90d 100644 --- a/fwp/libfwp/include/fwp_ac.h +++ b/fwp/libfwp/include/fwp_ac.h @@ -9,6 +9,7 @@ #include #include +#include #include "fwp_conf.h" #include "fwp_msgb.h" diff --git a/fwp/libfwp/src/fwp_ac.c b/fwp/libfwp/src/fwp_ac.c index 3d2fc82..ac5c5b8 100644 --- a/fwp/libfwp/src/fwp_ac.c +++ b/fwp/libfwp/src/fwp_ac.c @@ -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; } - diff --git a/fwp/libfwp/src/fwp_proto.c b/fwp/libfwp/src/fwp_proto.c index 8b2f8ba..b8e20ae 100644 --- a/fwp/libfwp/src/fwp_proto.c +++ b/fwp/libfwp/src/fwp_proto.c @@ -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; } diff --git a/fwp/libfwp/src/fwp_vres.c b/fwp/libfwp/src/fwp_vres.c index ce1ef1e..f7b97d6 100644 --- a/fwp/libfwp/src/fwp_vres.c +++ b/fwp/libfwp/src/fwp_vres.c @@ -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; diff --git a/fwp/tests/Makefile.omk b/fwp/tests/Makefile.omk index 032087b..ecf3bc8 100644 --- a/fwp/tests/Makefile.omk +++ b/fwp/tests/Makefile.omk @@ -1 +1,2 @@ -SUBDIRS= fwp_msgtest fwp_prototest unixsocktest +#SUBDIRS= fwp_msgtest fwp_prototest unixsocktest +SUBDIRS= fwp_prototest diff --git a/fwp/tests/fwp_prototest/Makefile.omk b/fwp/tests/fwp_prototest/Makefile.omk index 0aa0a9b..e82b769 100644 --- a/fwp/tests/fwp_prototest/Makefile.omk +++ b/fwp/tests/fwp_prototest/Makefile.omk @@ -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 diff --git a/fwp/tests/fwp_prototest/fwp_sendrecv_test.c b/fwp/tests/fwp_prototest/fwp_sendrecv_test.c index c6b3399..208d597 100644 --- a/fwp/tests/fwp_prototest/fwp_sendrecv_test.c +++ b/fwp/tests/fwp_prototest/fwp_sendrecv_test.c @@ -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) {