Commit d557dbcb authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

formatting

parent ce5a85ee
...@@ -50,96 +50,98 @@ int generate_packet(char * buf, int pnum){ ...@@ -50,96 +50,98 @@ int generate_packet(char * buf, int pnum){
//client //client
int main(int argc, char **argv) { int main(int argc, char **argv) {
struct timeval t0; struct timeval t0;
int fd; int fd;
char buffer[MAXLINE]; char buffer[MAXLINE];
int res = 0; int res = 0;
struct sockaddr_in servaddr; struct sockaddr_in servaddr;
in_addr_t s_addr = INADDR_ANY; in_addr_t s_addr = INADDR_ANY;
if (argc>1){ if (argc>1){
if (!inet_aton(argv[1],&s_addr)){ if (!inet_aton(argv[1],&s_addr)){
perror("Invalid inet addr in argv[1]"); perror("Invalid inet addr in argv[1]");
return -1; return -1;
}
} }
}
if ( (fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { if ( (fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed"); perror("socket creation failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(&servaddr, 0, sizeof(servaddr)); memset(&servaddr, 0, sizeof(servaddr));
// Server info // Server info
servaddr.sin_family = AF_INET; // IPv4 servaddr.sin_family = AF_INET; // IPv4
servaddr.sin_addr.s_addr = s_addr; servaddr.sin_addr.s_addr = s_addr;
servaddr.sin_port = htons(PORT); servaddr.sin_port = htons(PORT);
struct sockaddr_in saddr; struct sockaddr_in saddr;
memset(&saddr, 0, sizeof(struct sockaddr_in)); memset(&saddr, 0, sizeof(struct sockaddr_in));
saddr.sin_family = AF_INET; saddr.sin_family = AF_INET;
saddr.sin_port = htons(0); saddr.sin_port = htons(0);
saddr.sin_addr.s_addr = htonl(INADDR_ANY); saddr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))<0){ if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))<0){
printf("BIND ERROR!"); printf("BIND ERROR!");
} }
printf("Sending to %s:%d\n",inet_ntoa(servaddr.sin_addr),PORT); printf("Sending to %s:%d\n",inet_ntoa(servaddr.sin_addr),PORT);
int frame_cnt = 0; int frame_cnt = 0;
int pnum = 0; int pnum = 0;
if (connect(fd,(const struct sockaddr *) &servaddr, sizeof(servaddr))<0){ if (connect(fd,(const struct sockaddr *) &servaddr, sizeof(servaddr))<0){
printf("connect() error: %d",errno); printf("connect() error: %d",errno);
return -2; return -2;
} }
// Send // Send
while(true){ while(true){
random_string(buffer,MAXLINE); random_string(buffer,MAXLINE);
for(int i=0;i<NUMBER_OF_PACKETS_IN_FRAME;i++){ for(int i=0;i<NUMBER_OF_PACKETS_IN_FRAME;i++){
gettimeofday(&t0, NULL); gettimeofday(&t0, NULL);
printf("packet: %06d, time: %lu.%06d\n", pnum, t0.tv_sec, t0.tv_usec); printf("packet: %06d, time: %lu.%06d\n", pnum, t0.tv_sec, t0.tv_usec);
generate_packet(buffer,pnum); generate_packet(buffer,pnum);
// tested
//res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr));
// tested
//res = write(fd,(const char *)buffer,strlen(buffer));
//gettimeofday(&t0, NULL); // tested
//printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec); //res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr));
int iovcnt; // tested
struct iovec iov[3]; //res = write(fd,(const char *)buffer,strlen(buffer));
char *buf1 = "This is a longer string\n"; //gettimeofday(&t0, NULL);
char *buf2 = "This is the longest string in this example\n"; //printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
iov[0].iov_base = buffer;
iov[0].iov_len = strlen(buffer);
iov[1].iov_base = buf1;
iov[1].iov_len = strlen(buf1);
iov[2].iov_base = buf2;
iov[2].iov_len = strlen(buf2);
iovcnt = 3; int iovcnt;
struct iovec iov[3];
res = writev(fd,iov,iovcnt); char *buf1 = "This is a longer string\n";
char *buf2 = "This is the longest string in this example\n";
iov[0].iov_base = buffer;
iov[0].iov_len = strlen(buffer);
iov[1].iov_base = buf1;
iov[1].iov_len = strlen(buf1);
iov[2].iov_base = buf2;
iov[2].iov_len = strlen(buf2);
//gettimeofday(&t0, NULL); iovcnt = 3;
//printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
if (res<0){ res = writev(fd,iov,iovcnt);
printf(" send result= %d, errno= %d\n",res,errno);
}else{ //gettimeofday(&t0, NULL);
//printf(" sent %d bytes\n",res); //printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
}
if (res<0){
printf(" send result= %d, errno= %d\n",res,errno);
}else{
//printf(" sent %d bytes\n",res);
}
pnum++; pnum++;
} }
//printf("%s\n",buffer); //printf("%s\n",buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment