Commit c12e3e15c41c100a4808087709804fe4baf22ab1
1 parent
bcd0dad561
Exists in
master
RTT client server stringlen fix
Showing 4 changed files with 37 additions and 18 deletions Side-by-side Diff
network/overhead_client.c
View file @
c12e3e1
... | ... | @@ -54,9 +54,24 @@ |
54 | 54 | |
55 | 55 | //Calculate connection overhead client |
56 | 56 | start_delta+=diff(endtime,starttime); |
57 | - | |
57 | + int z; /* Status code */ | |
58 | + int s; /* Socket s */ | |
59 | + struct linger so_linger; | |
60 | + | |
61 | + so_linger.l_onoff = 1; | |
62 | + so_linger.l_linger = 0; | |
63 | + /*z = setsockopt(socket_fd, | |
64 | + SOL_SOCKET, | |
65 | + SO_LINGER, | |
66 | + &so_linger, | |
67 | + sizeof so_linger); | |
68 | + | |
69 | + if ( z ) | |
70 | + perror("setsockopt(2)"); | |
71 | + */ | |
58 | 72 | getTime(starttime); |
59 | 73 | shutdown(socket_fd, SHUT_RDWR); |
74 | + //close(socket_fd); | |
60 | 75 | getTime(endtime); |
61 | 76 | |
62 | 77 | //Calculate connection overhead server side |
network/random_str.c
View file @
c12e3e1
1 | 1 | #include<stdio.h> |
2 | 2 | #include<stdlib.h> |
3 | +#include<string.h> | |
3 | 4 | char* generate_string(int length) |
4 | 5 | { |
5 | 6 | //Random number seed |
6 | 7 | |
7 | 8 | |
... | ... | @@ -17,15 +18,15 @@ |
17 | 18 | { |
18 | 19 | char *buf; |
19 | 20 | buf = generate_string(5); |
20 | - printf("String of 5: %s", buf); | |
21 | + printf("String of 5: %s, size: %lu\n", buf, strlen(buf)); | |
21 | 22 | free(buf); |
22 | 23 | |
23 | 24 | buf = generate_string(40); |
24 | - printf("String of 5: %s", buf); | |
25 | + printf("String of 40: %s, size: %lu\n", buf, strlen(buf)); | |
25 | 26 | free(buf); |
26 | 27 | |
27 | 28 | buf = generate_string(80); |
28 | - printf("String of 5: %s", buf); | |
29 | + printf("String of 80: %s,, size: %lu\n", buf, strlen(buf)); | |
29 | 30 | free(buf); |
30 | 31 | |
31 | 32 | return 0; |
network/rtt_client.c
View file @
c12e3e1
... | ... | @@ -19,9 +19,9 @@ |
19 | 19 | //Random number seed |
20 | 20 | srand((unsigned int) ctime(0)); |
21 | 21 | char * buff; |
22 | - buff=(char *)malloc(sizeof(char)*length); | |
22 | + buff=(char *)malloc(sizeof(char)*(length+1)); | |
23 | 23 | int i; |
24 | - for(i=0;i< length-1;i++){ | |
24 | + for(i=0;i< length;i++){ | |
25 | 25 | buff[i] = rand() % rand() % (126 - 33 + 1) + 33; |
26 | 26 | } |
27 | 27 | buff[i] = '\0'; |
28 | 28 | |
... | ... | @@ -31,9 +31,9 @@ |
31 | 31 | int main(int argc, char*argv[]) |
32 | 32 | { |
33 | 33 | int socket_fd, rc; |
34 | - char buf[BUFFER_SIZE]; | |
34 | + char buff[BUFFER_SIZE]; | |
35 | 35 | char *msg; |
36 | - float start_delta = 0, close_delta = 0; | |
36 | + float delta = 0; | |
37 | 37 | if(argc<2){ |
38 | 38 | handle_error("<usage>:tcp_client <IP address>"); |
39 | 39 | } |
40 | 40 | |
41 | 41 | |
42 | 42 | |
... | ... | @@ -71,18 +71,18 @@ |
71 | 71 | //increase the sent message in strides of 64 |
72 | 72 | //look for for peak rtt |
73 | 73 | msg = generate_string(STRIDE_SIZE * i); |
74 | - printf("String Generated: \"%s\"",msg); | |
74 | + //printf("String Generated: \"%s\" size:%lu\n",msg, strlen(msg)); | |
75 | 75 | getTime(starttime); |
76 | - if(send(socket_fd, msg, sizeof(msg), 0) <0){ | |
77 | - handler_error("Send Error"); | |
76 | + if(send(socket_fd, msg, strlen(msg), 0) <0){ | |
77 | + handle_error("Send Error"); | |
78 | 78 | } |
79 | 79 | //The recv buffer size is same as the one we sent |
80 | - if(recv(socket_fd, buff, sizeof(msg), 0) != sizeof(msg)){ | |
80 | + if(recv(socket_fd, buff, strlen(msg), 0) != strlen(msg)){ | |
81 | 81 | handle_error("Data over/ Receive Error"); |
82 | 82 | } |
83 | 83 | getTime(endtime); |
84 | - delta+=diff(endtime, starttime); | |
85 | - printf("Single RTT %f", diff(endtime, starttime)); | |
84 | + delta+=(diff(endtime, starttime)); | |
85 | + printf("Single RTT %f\n", diff(endtime, starttime)); | |
86 | 86 | |
87 | 87 | } |
88 | 88 |
network/rtt_server.c
View file @
c12e3e1
... | ... | @@ -13,12 +13,13 @@ |
13 | 13 | do { perror(msg); exit(1);} while(0); |
14 | 14 | #define LISTEN_BACKLOG 100 |
15 | 15 | #define BUFFER_SIZE 2048 |
16 | +#define STRIDE_SIZE 64 | |
17 | +#define BACKLOG 32 | |
16 | 18 | |
17 | 19 | int main(int argc, char*argv[]) |
18 | 20 | { |
19 | 21 | int socket_fd, rc; |
20 | - char buff[BUFFER_SIZE], msg[BUFFER_SIZE]; | |
21 | - char | |
22 | + char buff[BUFFER_SIZE]; | |
22 | 23 | float setup_delta, close_delta; |
23 | 24 | if(argc<1){ |
24 | 25 | handle_error("<usage>:tcp_server"); |
25 | 26 | |
26 | 27 | |
... | ... | @@ -61,11 +62,13 @@ |
61 | 62 | } |
62 | 63 | for(i=1;i<=BACKLOG;i++) |
63 | 64 | { |
65 | + printf("%d\n",i); | |
64 | 66 | getTime(starttime); |
65 | - if(recv(connfd, buff, sizeof(i* STRIDE_SIZE), 0)!= sizeof(i* STRIDE_SIZE)){ | |
67 | + if(recv(connfd, buff,i* STRIDE_SIZE, 0) != i* STRIDE_SIZE){ | |
68 | + printf("String :%s, strlen:%d, stride:%d\n", buff, strlen(buff), i*STRIDE_SIZE); | |
66 | 69 | handle_error("Receive Error/ Data Done"); |
67 | 70 | } |
68 | - if(send(connfd, buff, sizeof(i * STRIDE_SIZE), 0)<0){ | |
71 | + if(send(connfd, buff,i * STRIDE_SIZE, 0)<0){ | |
69 | 72 | handle_error("Send Error"); |
70 | 73 | } |
71 | 74 | getTime(endtime); |