]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/demo/receiver.c
3821efef35b6ddf25e68cbc67e0254fac5bb6474
[frescor/frsh-forb.git] / src / fwp / fwp / demo / receiver.c
1 /**
2  * \file reciever.c  
3  *
4  */
5 #include <frsh.h>
6 #include "test_config.h"
7
8 #include <errno.h>
9 #include <stdio.h>
10 #include <pthread.h>
11
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <wvtest.h>
16 #include <fwp_res.h>
17
18 char msg[MSGBUFFSIZE];
19
20 frsh_resource_id_t resource_id = TEST_RESOURCE_ID;
21 frsh_stream_id_t stream_id = TEST_STREAM_ID;
22 long int num_msg = TEST_NUM_MSG;
23 size_t msg_size = MSGBUFFSIZE;
24         
25 int receiver()
26 {
27         size_t len;
28         frsh_receive_endpoint_t repoint;
29         int count;
30
31         frsh_network_address_t  from;
32         frsh_receive_endpoint_protocol_info_t recv_pinfo;
33         frsh_endpoint_queueing_info_t qinfo;
34         
35         recv_pinfo.body = NULL;
36
37         /* local_addr should be handled when creating socket */
38         //TODO: Segmentation fault in wvtest.sh file after calling WVPASSNE     
39         //WVPASSNE(frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo, &repoint), 0);
40         if (frsh_receive_endpoint_create(resource_id, stream_id, qinfo, recv_pinfo, 
41                         &repoint) != 0){
42                 return 0;
43         }
44         count = 0;
45         while (count != num_msg){
46                 count++;
47                 WVPASSEQ(frsh_receive_sync(repoint, msg, msg_size, &len, &from), msg_size);
48         }
49         
50         /* TODO: destroy vres and send enpoint */
51
52         return 1;
53 }
54
55 int main(int argc, char* argv[])
56 {
57         int opt;
58         opterr = 0;
59
60         bool opt_daemon = false;
61         char *opt_pidfile = NULL;
62
63         while ((opt = getopt (argc, argv, "e:p:m:")) != -1) {
64
65                 switch (opt) {
66                         case 'e':
67                                 opt_daemon = true;
68                                 opt_pidfile = optarg;
69                                 break;
70                         case 'p':
71                                 stream_id = atoi(optarg);
72                                 break;
73                         case 'm':
74                                 num_msg = atoi(optarg);
75                                 break;
76                         case '?':
77                                 printf("Usage: %s -e -p stream_id -m num_msg\n", 
78                                                 argv[0]); 
79                 }
80         }
81
82         if (opt_daemon)
83                 forb_daemon_prepare(opt_pidfile);
84         
85         WVFRSH(frsh_init());
86         WVPASSEQ(receiver(), 1);
87
88         return 0;
89 }
90