From c12e3e15c41c100a4808087709804fe4baf22ab1 Mon Sep 17 00:00:00 2001 From: Ajay Mohan Date: Sat, 12 Mar 2016 11:48:53 -0800 Subject: [PATCH] RTT client server stringlen fix --- network/overhead_client.c | 17 ++++++++++++++++- network/random_str.c | 7 ++++--- network/rtt_client.c | 20 ++++++++++---------- network/rtt_server.c | 11 +++++++---- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/network/overhead_client.c b/network/overhead_client.c index 241fa1a..d882440 100644 --- a/network/overhead_client.c +++ b/network/overhead_client.c @@ -54,9 +54,24 @@ int main(int argc, char*argv[]) //Calculate connection overhead client start_delta+=diff(endtime,starttime); - + int z; /* Status code */ + int s; /* Socket s */ + struct linger so_linger; + + so_linger.l_onoff = 1; + so_linger.l_linger = 0; + /*z = setsockopt(socket_fd, + SOL_SOCKET, + SO_LINGER, + &so_linger, + sizeof so_linger); + + if ( z ) + perror("setsockopt(2)"); + */ getTime(starttime); shutdown(socket_fd, SHUT_RDWR); + //close(socket_fd); getTime(endtime); //Calculate connection overhead server side diff --git a/network/random_str.c b/network/random_str.c index 7f765d5..7d1f452 100644 --- a/network/random_str.c +++ b/network/random_str.c @@ -1,5 +1,6 @@ #include #include +#include char* generate_string(int length) { //Random number seed @@ -17,15 +18,15 @@ int main() { char *buf; buf = generate_string(5); - printf("String of 5: %s", buf); + printf("String of 5: %s, size: %lu\n", buf, strlen(buf)); free(buf); buf = generate_string(40); - printf("String of 5: %s", buf); + printf("String of 40: %s, size: %lu\n", buf, strlen(buf)); free(buf); buf = generate_string(80); - printf("String of 5: %s", buf); + printf("String of 80: %s,, size: %lu\n", buf, strlen(buf)); free(buf); return 0; diff --git a/network/rtt_client.c b/network/rtt_client.c index 3a743d6..8554910 100644 --- a/network/rtt_client.c +++ b/network/rtt_client.c @@ -19,9 +19,9 @@ char* generate_string(int length) //Random number seed srand((unsigned int) ctime(0)); char * buff; - buff=(char *)malloc(sizeof(char)*length); + buff=(char *)malloc(sizeof(char)*(length+1)); int i; - for(i=0;i< length-1;i++){ + for(i=0;i< length;i++){ buff[i] = rand() % rand() % (126 - 33 + 1) + 33; } buff[i] = '\0'; @@ -31,9 +31,9 @@ char* generate_string(int length) int main(int argc, char*argv[]) { int socket_fd, rc; - char buf[BUFFER_SIZE]; + char buff[BUFFER_SIZE]; char *msg; - float start_delta = 0, close_delta = 0; + float delta = 0; if(argc<2){ handle_error(":tcp_client "); } @@ -71,18 +71,18 @@ int main(int argc, char*argv[]) //increase the sent message in strides of 64 //look for for peak rtt msg = generate_string(STRIDE_SIZE * i); - printf("String Generated: \"%s\"",msg); + //printf("String Generated: \"%s\" size:%lu\n",msg, strlen(msg)); getTime(starttime); - if(send(socket_fd, msg, sizeof(msg), 0) <0){ - handler_error("Send Error"); + if(send(socket_fd, msg, strlen(msg), 0) <0){ + handle_error("Send Error"); } //The recv buffer size is same as the one we sent - if(recv(socket_fd, buff, sizeof(msg), 0) != sizeof(msg)){ + if(recv(socket_fd, buff, strlen(msg), 0) != strlen(msg)){ handle_error("Data over/ Receive Error"); } getTime(endtime); - delta+=diff(endtime, starttime); - printf("Single RTT %f", diff(endtime, starttime)); + delta+=(diff(endtime, starttime)); + printf("Single RTT %f\n", diff(endtime, starttime)); } diff --git a/network/rtt_server.c b/network/rtt_server.c index 2ff16a1..35a987c 100644 --- a/network/rtt_server.c +++ b/network/rtt_server.c @@ -13,12 +13,13 @@ do { perror(msg); exit(1);} while(0); #define LISTEN_BACKLOG 100 #define BUFFER_SIZE 2048 +#define STRIDE_SIZE 64 +#define BACKLOG 32 int main(int argc, char*argv[]) { int socket_fd, rc; - char buff[BUFFER_SIZE], msg[BUFFER_SIZE]; - char + char buff[BUFFER_SIZE]; float setup_delta, close_delta; if(argc<1){ handle_error(":tcp_server"); @@ -61,11 +62,13 @@ int main(int argc, char*argv[]) } for(i=1;i<=BACKLOG;i++) { + printf("%d\n",i); getTime(starttime); - if(recv(connfd, buff, sizeof(i* STRIDE_SIZE), 0)!= sizeof(i* STRIDE_SIZE)){ + if(recv(connfd, buff,i* STRIDE_SIZE, 0) != i* STRIDE_SIZE){ + printf("String :%s, strlen:%d, stride:%d\n", buff, strlen(buff), i*STRIDE_SIZE); handle_error("Receive Error/ Data Done"); } - if(send(connfd, buff, sizeof(i * STRIDE_SIZE), 0)<0){ + if(send(connfd, buff,i * STRIDE_SIZE, 0)<0){ handle_error("Send Error"); } getTime(endtime); -- 1.9.1