-
Notifications
You must be signed in to change notification settings - Fork 0
/
only_rec.c
86 lines (51 loc) · 1.77 KB
/
only_rec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "quick.c"
int main(int argc, char **argv)
{
string filename;
pthread_mutex_init(&rec_Q_mutex, NULL);
sem_init(&rec_full,0,0);
sem_init(&rec_empty,0,RECV_Q_LIMIT);
if (argc != 2 && argc !=3) {
printf("Arguments provided: %d\n",argc);
fprintf(stderr, "usage: %s <port_for_server>\n", argv[0]);
exit(1);
}
//portno = atoi(argv[1]);
// socket: create the socket
if (argc==3)
drop_prob=atof(argv[2]);
setup_at(atoi(argv[1]));
int rec_filesize, rec_remain_data;
srand(time(0));
/*
* recvfrom: receive a UDP datagram from a client
*/
filedata metadata=getfilename_and_size(clientaddr,clientlen);
filename=metadata.filename;
rec_filesize=metadata.filesize;
printf("filename : %s , filesize: %d \n",filename.c_str(), rec_filesize);
rec_remain_data = rec_filesize;
FILE *received_file= fopen(filename.c_str(), "ab");
init_receiver_modules(clientaddr,clientlen);
while(1)
{
if(rec_remain_data>0)
{
rec_data_node data_received;
if(rec_remain_data>BUFSIZE)
data_received=changedappRecv(BUFSIZE);
else
data_received=changedappRecv(rec_remain_data);
rec_remain_data -=data_received.bytes;
fwrite(data_received.data,1,data_received.bytes,received_file);
//printf("data RECIEVED: %s\n\n",data_received.data );
}
else
{
break;
}
}
close_instance();
printf("Thread Joined\n" );
fclose(received_file);
}