]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/fwp/fwp/demo/receiver.c
fwp: adaptive test updated
[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 void* 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 NULL;
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 NULL;
53 }
54
55 int main(int argc, char* argv[])
56 {
57         pthread_attr_t  thattr;
58         pthread_t       thread;
59         int opt;
60         opterr = 0;
61
62         bool opt_daemon = false;
63         char *opt_pidfile = NULL;
64
65         while ((opt = getopt (argc, argv, "e:p:m:")) != -1) {
66
67                 switch (opt) {
68                         case 'e':
69                                 opt_daemon = true;
70                                 opt_pidfile = optarg;
71                                 break;
72                         case 'p':
73                                 stream_id = atoi(optarg);
74                                 break;
75                         case 'm':
76                                 num_msg = atoi(optarg);
77                         case '?':
78                                 printf("Usage: %s -e -p stream_id -m num_msg\n", 
79                                                 argv[0]); 
80                 }
81         }
82
83         if (opt_daemon)
84                 forb_daemon_prepare(opt_pidfile);
85         
86         WVFRSH(frsh_init());
87         WVPASSEQ(pthread_attr_init(&thattr), 0);
88         WVPASSEQ(pthread_create(&thread, &thattr, receiver, NULL), 0); 
89         WVPASSEQ(pthread_join(thread, (void**) NULL), 0);       
90
91         return 0;
92 }
93