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