/* * memcpclient.c - client program for remote copy */ #include #include #include #include "memcp.h" #define MEGA 1000000 #define PROT "udp" #define UDPSIZE 8700 main(argc, argv) int argc; char *argv[]; { CLIENT *cl; /* RPC handle */ char *server; /* server name */ int repeats; /* number of times to repeat */ int i, j; int isUDP; int bytesRemain, bytesToSend; struct memPass *result; /* return result */ struct memPass message; /* sturcture that carries the string and size */ struct timeval tp; struct timezone tzp; long startSec, startUsec, endSec, endUsec; double accumTime; double tmpTime; if (argc != 4) { fprintf(stderr, "usage: %s hostname size_of_read repeats\n",argv[0]); exit(1); } server = argv[1]; bytesToSend = atoi(argv[2]); repeats = atoi(argv[3]); if (strcmp(PROT,"udp") == 0) isUDP = 1; /* uses UDP protocol */ else isUDP = 0; /* * Create the client "handle" */ if ( (cl = clnt_create(server, MEM_PROG, MEM_VERS, PROT)) == NULL) { /* * Couldn't establish connection with server; */ clnt_pcreateerror(server); exit(2); } /* * First call the remote procedure "mem_copy" */ accumTime = 0; message.contents = (char *)malloc(bytesToSend); for (i = 0; i < repeats; i ++) { message.bytes = bytesToSend; for (j = 0; j < message.bytes; j ++) message.contents[j] = 'a'; message.contents[j] = 0; message.flag = 0; /* 0 for send, 1 for receive */ result = NULL; /* initialize */ gettimeofday(&tp,&tzp); startSec = tp.tv_sec; startUsec = tp.tv_usec; if ((isUDP == 0) || message.bytes <= UDPSIZE) /* no need to break up packet */ { if ( (result = mem_copy_1(&message, cl)) == NULL) { clnt_perror(cl, server); exit(3); } } else /* use UDP, break up the packet */ { bytesRemain = message.bytes; message.bytes = UDPSIZE; message.contents[UDPSIZE] = 0; /* reduce the size of contents */ while (bytesRemain > 0) { if ( (result = mem_copy_1(&message, cl)) == NULL) { clnt_perror(cl, server); exit(3); } bytesRemain = bytesRemain - message.bytes; if (bytesRemain < UDPSIZE) { message.bytes = bytesRemain; message.contents[bytesRemain] = 0; } } } gettimeofday(&tp,&tzp); endSec = tp.tv_sec; endUsec = tp.tv_usec; tmpTime = endUsec - startUsec; if (tmpTime < 0) { tmpTime = (tmpTime + MEGA); endSec = endSec - 1; } tmpTime = (endSec - startSec) + tmpTime/MEGA; accumTime = accumTime + tmpTime; /* printf("end/start sec %d / %d end/start usec %d / %d\n", endSec,startSec,endUsec,startUsec); printf("%f\n",tmpTime); */ } /* printf(" accumulated time: %f\n",accumTime); */ printf(" average time: %f size: %d\n",accumTime/repeats,bytesToSend); /* if (strcmp(result->contents,message.contents) == 0) printf(" message sent and received are the same \n"); else printf(" message sent and received differ \n"); if (result->flag == 1) printf(" flag correct \n"); else printf(" flag incorrect \n"); printf("number of chars asked / received from host %s = %d / %d\n", server, message.bytes, result->bytes); */ clnt_destroy(cl); exit(0); }