]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/tests/fwp_prototest/fwp_sendrecv_test2.c
Compilation fixes in tests
[frescor/fwp.git] / fwp / tests / fwp_prototest / fwp_sendrecv_test2.c
1 #define CONFIGURE_FWP_MNGT 0
2 #include "fwp_confdefs.h"
3 #include "fwp.h"
4
5 #include <errno.h>
6 #include <stdio.h>
7 #include <pthread.h>
8
9 fwp_endpoint_attr_t  attr;
10
11 void* receiver(void* arg)
12 {
13         fwp_endpoint_d_t repoint_d1;
14         int i,len;
15         char buffer[30];
16         
17         FWP_DEBUG("Creating receive endpoint\n");
18         if (fwp_receive_endpoint_create(7777, &attr,&repoint_d1) < 0){
19                 perror("Error while creating receive endpoint\n");
20                 return NULL;
21         }
22                 
23         FWP_DEBUG("Receive endpoint created \n");
24         for (i = 0; i < 3; i++) {
25                 if ((len = fwp_recv(repoint_d1, buffer, sizeof(buffer), 0)) < 0) {
26                         perror("Error while receiving data::");
27                         return NULL;
28                 } else {
29                         printf("Received %s\n",buffer);
30                         //for (j = 0 ; j < 10; i++)
31                         //      printf("%c", buffer[i]);
32
33                 }
34                 printf("END\n");
35         }
36
37         return NULL;
38 }
39
40 int main()
41 {
42         fwp_vres_d_t vres_d1;
43         struct fwp_vres_params vparam1, vparam2;
44         char msg1[] = "Hello1";
45         char msg2[] = "Hello2";
46         fwp_endpoint_d_t sepoint_d1;
47         pthread_t id;
48         
49         vparam1.ac_id = FWP_AC_VO; 
50         vparam1.budget = 100;
51         vparam1.period_usec = 10; 
52
53         vparam2.ac_id = FWP_AC_BK; 
54         vparam2.budget = 100;
55         vparam2.period_usec = 100;
56
57         printf("Start\n");
58         if (fwp_init() != 0) {
59                 printf("FWP initialization failed!\n");
60                 return -1;
61         }
62         
63         fwp_endpoint_attr_init(&attr);
64         fwp_endpoint_attr_setreliability(&attr, FWP_EPOINT_RELIABLE);
65         
66         pthread_create(&id, NULL, &receiver, (void*) NULL);
67         printf("Create vres1, vres2\n");
68         if (fwp_vres_create(&vparam1, &vres_d1) < 0) {
69                 printf("Unable to create vres1\n");
70                 return -1;
71         }
72         printf("Vres1 created \n");
73         
74         if (fwp_send_endpoint_create(inet_addr("127.0.0.1"), 7777, &attr, 
75                                         &sepoint_d1) < 0) {
76                 return -1;
77         }
78         printf("Send endpoint 1 created\n");
79         fwp_send_endpoint_bind(sepoint_d1, vres_d1);
80         
81         fwp_send(sepoint_d1, msg1, sizeof(msg1), 0);
82         FWP_DEBUG("Sent msg1\n");
83         fwp_send(sepoint_d1, msg2, sizeof(msg2), 0);
84         FWP_DEBUG("Sent msg2\n");
85
86         /*if (fwp_vres_destroy(vres_d1) < 0) {
87                 perror("Unable to destroy vres1\n");
88                 return -1;
89         }
90         printf("Vres1 destroyed\n");
91         
92         if (fwp_vres_destroy(vres_d2) < 0){
93                 perror("Unable to destroy vres2\n");
94                 return -1;
95         }       
96         printf("Vres2 destroyed\n");
97         */
98
99         printf("Test PASSED!\n");
100         scanf("Press key");     
101         
102         return 0;
103 }