version 1.1.1.1.2.1, 2013/07/22 00:49:29
|
version 1.1.1.1.2.2, 2016/10/18 13:26:43
|
Line 52
|
Line 52
|
#include <arpa/inet.h> |
#include <arpa/inet.h> |
#include <netdb.h> |
#include <netdb.h> |
#include <sys/time.h> /* struct timeval */ |
#include <sys/time.h> /* struct timeval */ |
|
#include <unistd.h> |
|
#include <string.h> |
|
#include <stdlib.h> |
|
|
#if defined(SYSV) |
#if defined(SYSV) |
#include <sys/times.h> |
#include <sys/times.h> |
Line 130 double cput, realt; /* user, real time (seconds) */
|
Line 133 double cput, realt; /* user, real time (seconds) */
|
|
|
void err(); |
void err(); |
void mes(); |
void mes(); |
int pattern(); | void pattern(); |
void prep_timer(); |
void prep_timer(); |
double read_timer(); |
double read_timer(); |
int Nread(); |
int Nread(); |
Line 144 sigpipe()
|
Line 147 sigpipe()
|
{ |
{ |
} |
} |
|
|
|
int |
main(argc,argv) |
main(argc,argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
Line 246 char **argv;
|
Line 250 char **argv;
|
#endif /* cray */ |
#endif /* cray */ |
} |
} |
sinhim.sin_port = htons(port); |
sinhim.sin_port = htons(port); |
|
sinme.sin_family = AF_INET; /* Solaris needs this */ |
sinme.sin_port = 0; /* free choice */ |
sinme.sin_port = 0; /* free choice */ |
} else { |
} else { |
/* rcvr */ |
/* rcvr */ |
Line 260 char **argv;
|
Line 265 char **argv;
|
if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL) |
if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL) |
err("malloc"); |
err("malloc"); |
if (bufalign != 0) |
if (bufalign != 0) |
buf +=(bufalign - ((int)buf % bufalign) + bufoffset) % bufalign; | buf += (bufalign |
| -((unsigned long)buf % bufalign) |
| + bufoffset) % bufalign; |
|
|
if (trans) { |
if (trans) { |
fprintf(stdout, | fprintf(stderr, |
"ttcp-t: buflen=%d, nbuf=%d, align=%d/%d, port=%d", |
"ttcp-t: buflen=%d, nbuf=%d, align=%d/%d, port=%d", |
buflen, nbuf, bufalign, bufoffset, port); |
buflen, nbuf, bufalign, bufoffset, port); |
if (sockbufsize) |
if (sockbufsize) |
fprintf(stdout, ", sockbufsize=%d", sockbufsize); | fprintf(stderr, ", sockbufsize=%d", sockbufsize); |
fprintf(stdout, " %s -> %s\n", udp?"udp":"tcp", host); | fprintf(stderr, " %s -> %s\n", udp?"udp":"tcp", host); |
} else { |
} else { |
fprintf(stdout, | fprintf(stderr, |
"ttcp-r: buflen=%d, nbuf=%d, align=%d/%d, port=%d", |
"ttcp-r: buflen=%d, nbuf=%d, align=%d/%d, port=%d", |
buflen, nbuf, bufalign, bufoffset, port); |
buflen, nbuf, bufalign, bufoffset, port); |
if (sockbufsize) |
if (sockbufsize) |
fprintf(stdout, ", sockbufsize=%d", sockbufsize); | fprintf(stderr, ", sockbufsize=%d", sockbufsize); |
fprintf(stdout, " %s\n", udp?"udp":"tcp"); | fprintf(stderr, " %s\n", udp?"udp":"tcp"); |
} |
} |
|
|
if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) |
if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) |
err("socket"); |
err("socket"); |
mes("socket"); |
mes("socket"); |
|
|
if (bind(fd, &sinme, sizeof(sinme)) < 0) | if (bind(fd, (struct sockaddr *) &sinme, sizeof(sinme)) < 0) |
err("bind"); |
err("bind"); |
|
|
#if defined(SO_SNDBUF) || defined(SO_RCVBUF) |
#if defined(SO_SNDBUF) || defined(SO_RCVBUF) |
Line 323 char **argv;
|
Line 330 char **argv;
|
mes("nodelay"); |
mes("nodelay"); |
} |
} |
#endif |
#endif |
if(connect(fd, &sinhim, sizeof(sinhim) ) < 0) | if(connect(fd, (struct sockaddr*)&sinhim, sizeof(sinhim) ) < 0) |
err("connect"); |
err("connect"); |
mes("connect"); |
mes("connect"); |
} else { |
} else { |
Line 455 char *s;
|
Line 462 char *s;
|
fprintf(stderr,"ttcp%s: %s\n", trans?"-t":"-r", s); |
fprintf(stderr,"ttcp%s: %s\n", trans?"-t":"-r", s); |
} |
} |
|
|
|
void |
pattern( cp, cnt ) |
pattern( cp, cnt ) |
register char *cp; |
register char *cp; |
register int cnt; |
register int cnt; |
Line 638 prusage(r0, r1, e, b, outp)
|
Line 646 prusage(r0, r1, e, b, outp)
|
break; |
break; |
|
|
case 'X': |
case 'X': |
sprintf(outp,"%d", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t); | sprintf(outp,"%ld", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'D': |
case 'D': |
sprintf(outp,"%d", t == 0 ? 0 : | sprintf(outp,"%ld", t == 0 ? 0 : |
(r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t); |
(r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'K': |
case 'K': |
sprintf(outp,"%d", t == 0 ? 0 : | sprintf(outp,"%ld", t == 0 ? 0 : |
((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) - |
((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) - |
(r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t); |
(r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'M': |
case 'M': |
sprintf(outp,"%d", r1->ru_maxrss/2); | sprintf(outp,"%ld", r1->ru_maxrss/2); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'F': |
case 'F': |
sprintf(outp,"%d", r1->ru_majflt-r0->ru_majflt); | sprintf(outp,"%ld", r1->ru_majflt-r0->ru_majflt); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'R': |
case 'R': |
sprintf(outp,"%d", r1->ru_minflt-r0->ru_minflt); | sprintf(outp,"%ld", r1->ru_minflt-r0->ru_minflt); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'I': |
case 'I': |
sprintf(outp,"%d", r1->ru_inblock-r0->ru_inblock); | sprintf(outp,"%ld", r1->ru_inblock-r0->ru_inblock); |
END(outp); |
END(outp); |
break; |
break; |
|
|
case 'O': |
case 'O': |
sprintf(outp,"%d", r1->ru_oublock-r0->ru_oublock); | sprintf(outp,"%ld", r1->ru_oublock-r0->ru_oublock); |
END(outp); |
END(outp); |
break; |
break; |
case 'C': |
case 'C': |
sprintf(outp,"%d+%d", r1->ru_nvcsw-r0->ru_nvcsw, | sprintf(outp,"%ld+%ld", r1->ru_nvcsw-r0->ru_nvcsw, |
r1->ru_nivcsw-r0->ru_nivcsw ); |
r1->ru_nivcsw-r0->ru_nivcsw ); |
END(outp); |
END(outp); |
break; |
break; |
Line 739 register char *cp;
|
Line 747 register char *cp;
|
/* |
/* |
* N R E A D |
* N R E A D |
*/ |
*/ |
|
int |
Nread( fd, buf, count ) |
Nread( fd, buf, count ) |
int fd; |
int fd; |
void *buf; |
void *buf; |
Line 770 int count;
|
Line 779 int count;
|
/* |
/* |
* N W R I T E |
* N W R I T E |
*/ |
*/ |
|
int |
Nwrite( fd, buf, count ) |
Nwrite( fd, buf, count ) |
int fd; |
int fd; |
void *buf; |
void *buf; |
Line 778 int count;
|
Line 788 int count;
|
register int cnt; |
register int cnt; |
if( udp ) { |
if( udp ) { |
again: |
again: |
cnt = sendto( fd, buf, count, 0, &sinhim, sizeof(sinhim) ); | cnt = sendto( fd, buf, count, 0, (struct sockaddr *)&sinhim, sizeof(sinhim) ); |
numCalls++; |
numCalls++; |
if( cnt<0 && errno == ENOBUFS ) { |
if( cnt<0 && errno == ENOBUFS ) { |
delay(18000); |
delay(18000); |
Line 799 delay(us)
|
Line 809 delay(us)
|
|
|
tv.tv_sec = 0; |
tv.tv_sec = 0; |
tv.tv_usec = us; |
tv.tv_usec = us; |
(void)select( 1, (char *)0, (char *)0, (char *)0, &tv ); | (void)select( 1, NULL, NULL, NULL, &tv ); |
} |
} |
|
|
/* |
/* |