<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 8, 2021, 12:12 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Are these updates from OAR? Do you want to scope them with #ifdef<br>
#endif for RTEMS? Or this is clone-and-own software now?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yes. The code is old a s has warnings which need to be fixed.</div><div dir="auto"><br></div><div dir="auto">Because this program gets compiled natively when running benchmarks. It takes a Tx and Rx side to run. One is on your host.</div><div dir="auto"><br></div><div dir="auto">I have no idea how to mark things like this </div><div dir="auto"><br></div><div dir="auto">The old version was clone and own. This may just be a newer version of that but it needs to run on various hosts and RTEMS. </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Why not import from network-demos?</blockquote></div></div><div dir="auto"><br></div><div dir="auto"></div><div dir="auto">I thought it would be best to do a fresh port using that as guidance so there was less chance of picking up cruft along the way.</div><div dir="auto"><br></div><div dir="auto">--joel</div><div dir="auto"></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On Tue, Jun 8, 2021 at 10:12 AM Stephen Clark <<a href="mailto:stephen.clark@oarcorp.com" target="_blank" rel="noreferrer">stephen.clark@oarcorp.com</a>> wrote:<br>
><br>
> Updated the TTCP code to match the ttcp.c in RTEMS network-demos<br>
> repository (<a href="https://git.rtems.org/network-demos/" rel="noreferrer noreferrer" target="_blank">https://git.rtems.org/network-demos/</a>).<br>
> ---<br>
> rtemsbsd/ttcp/ttcp.c | 91 +++++++++++++++++++++++++++++++-------------<br>
> 1 file changed, 65 insertions(+), 26 deletions(-)<br>
><br>
> diff --git a/rtemsbsd/ttcp/ttcp.c b/rtemsbsd/ttcp/ttcp.c<br>
> index 305a7c7d..dc62c64b 100644<br>
> --- a/rtemsbsd/ttcp/ttcp.c<br>
> +++ b/rtemsbsd/ttcp/ttcp.c<br>
> @@ -35,8 +35,9 @@<br>
> * Distribution Status -<br>
> * Public Domain. Distribution Unlimited.<br>
> */<br>
> +<br>
> #ifndef lint<br>
> -static char RCSid[] = "ttcp.c $Revision$";<br>
> +/* static char RCSid[] = "ttcp.c $Revision$"; */<br>
> #endif<br>
><br>
> #define BSD43<br>
> @@ -44,6 +45,8 @@ static char RCSid[] = "ttcp.c $Revision$";<br>
> /* #define BSD41a */<br>
> /* #define SYSV */ /* required on SGI IRIX releases before 3.3 */<br>
><br>
> +#define ENABLE_NANOSLEEP_DELAY<br>
> +<br>
> #include <stdio.h><br>
> #include <signal.h><br>
> #include <ctype.h><br>
> @@ -54,8 +57,12 @@ static char RCSid[] = "ttcp.c $Revision$";<br>
> #include <netinet/tcp.h><br>
> #include <arpa/inet.h><br>
> #include <netdb.h><br>
> +#include <string.h><br>
> #include <sys/time.h> /* struct timeval */<br>
><br>
> +#include <unistd.h><br>
> +#include <stdlib.h><br>
> +<br>
> #if defined(SYSV)<br>
> #include <sys/times.h><br>
> #include <sys/param.h><br>
> @@ -71,7 +78,13 @@ struct sockaddr_in sinme;<br>
> struct sockaddr_in sinhim;<br>
> struct sockaddr_in frominet;<br>
><br>
> -int domain, fromlen;<br>
> +/* these make it easier to avoid warnings */<br>
> +struct sockaddr *sinhim_p = (struct sockaddr *) &sinhim;<br>
> +struct sockaddr *sinme_p = (struct sockaddr *) &sinme;<br>
> +struct sockaddr *frominet_p = (struct sockaddr *) &frominet;<br>
> +<br>
> +int domain;<br>
> +socklen_t fromlen;<br>
> int fd; /* fd of network socket */<br>
><br>
> int buflen = 8 * 1024; /* length of buffer */<br>
> @@ -97,6 +110,7 @@ char fmt = 'K'; /* output format: k = kilobits, K = kilobytes,<br>
> * m = megabits, M = megabytes,<br>
> * g = gigabits, G = gigabytes */<br>
> int touchdata = 0; /* access data after reading */<br>
> +long milliseconds = 0; /* delay in milliseconds */<br>
><br>
> struct hostent *addr;<br>
> extern int errno;<br>
> @@ -124,6 +138,7 @@ Options specific to -t:\n\<br>
> Options specific to -r:\n\<br>
> -B for -s, only output full blocks as specified by -l (for TAR)\n\<br>
> -T \"touch\": access each byte as it's read\n\<br>
> + -m ## delay for specified milliseconds between each write\n\<br>
> ";<br>
><br>
> char stats[128];<br>
> @@ -133,7 +148,7 @@ double cput, realt; /* user, real time (seconds) */<br>
><br>
> void err();<br>
> void mes();<br>
> -int pattern();<br>
> +void pattern();<br>
> void prep_timer();<br>
> double read_timer();<br>
> int Nread();<br>
> @@ -147,7 +162,18 @@ sigpipe()<br>
> {<br>
> }<br>
><br>
> -main(argc,argv)<br>
> +void millisleep(long msec)<br>
> +{<br>
> +#if defined(ENABLE_NANOSLEEP_DELAY)<br>
> + struct timespec req;<br>
> +<br>
> + req.tv_sec = msec / 1000;<br>
> + req.tv_nsec = (msec % 1000) * 1000000;<br>
> +<br>
> + nanosleep( &req, NULL );<br>
> +#endif<br>
> +}<br>
> +int main(argc,argv)<br>
> int argc;<br>
> char **argv;<br>
> {<br>
> @@ -156,7 +182,7 @@ char **argv;<br>
><br>
> if (argc < 2) goto usage;<br>
><br>
> - while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:")) != -1) {<br>
> + while ((c = getopt(argc, argv, "drstuvBDTb:f:l:m:n:p:A:O:")) != -1) {<br>
> switch (c) {<br>
><br>
> case 'B':<br>
> @@ -179,6 +205,12 @@ char **argv;<br>
> "ttcp: -D option ignored: TCP_NODELAY socket option not supported\n");<br>
> #endif<br>
> break;<br>
> + case 'm':<br>
> + milliseconds = atoi(optarg);<br>
> + #if !defined(ENABLE_NANOSLEEP_DELAY)<br>
> + fprintf(stderr, "millisecond delay disabled\n");<br>
> + #endif<br>
> + break;<br>
> case 'n':<br>
> nbuf = atoi(optarg);<br>
> break;<br>
> @@ -285,7 +317,7 @@ char **argv;<br>
> err("socket");<br>
> mes("socket");<br>
><br>
> - if (bind(fd, &sinme, sizeof(sinme)) < 0)<br>
> + if (bind(fd, sinme_p, sizeof(sinme)) < 0)<br>
> err("bind");<br>
><br>
> #if defined(SO_SNDBUF) || defined(SO_RCVBUF)<br>
> @@ -305,7 +337,9 @@ char **argv;<br>
> #endif<br>
><br>
> if (!udp) {<br>
> +#if !defined(__rtems__)<br>
> signal(SIGPIPE, sigpipe);<br>
> +#endif<br>
> if (trans) {<br>
> /* We are the client if transmitting */<br>
> if (options) {<br>
> @@ -326,7 +360,7 @@ char **argv;<br>
> mes("nodelay");<br>
> }<br>
> #endif<br>
> - if(connect(fd, &sinhim, sizeof(sinhim) ) < 0)<br>
> + if(connect(fd, sinhim_p, sizeof(sinhim) ) < 0)<br>
> err("connect");<br>
> mes("connect");<br>
> } else {<br>
> @@ -348,11 +382,11 @@ char **argv;<br>
> }<br>
> fromlen = sizeof(frominet);<br>
> domain = AF_INET;<br>
> - if((fd=accept(fd, &frominet, &fromlen) ) < 0)<br>
> + if((fd=accept(fd, frominet_p, &fromlen) ) < 0)<br>
> err("accept");<br>
> { struct sockaddr_in peer;<br>
> - int peerlen = sizeof(peer);<br>
> - if (getpeername(fd, (struct sockaddr_in *) &peer,<br>
> + socklen_t peerlen = sizeof(peer);<br>
> + if (getpeername(fd, (struct sockaddr *) &peer,<br>
> &peerlen) < 0) {<br>
> err("getpeername");<br>
> }<br>
> @@ -368,8 +402,10 @@ char **argv;<br>
> if (trans) {<br>
> pattern( buf, buflen );<br>
> if(udp) (void)Nwrite( fd, buf, 4 ); /* rcvr start */<br>
> - while (nbuf-- && Nwrite(fd,buf,buflen) == buflen)<br>
> + while (nbuf-- && Nwrite(fd,buf,buflen) == buflen) {<br>
> nbytes += buflen;<br>
> + millisleep( milliseconds );<br>
> + }<br>
> if(udp) (void)Nwrite( fd, buf, 4 ); /* rcvr end */<br>
> } else {<br>
> if (udp) {<br>
> @@ -423,7 +459,7 @@ char **argv;<br>
> nbytes, cput, outfmt(nbytes/cput));<br>
> }<br>
> fprintf(stdout,<br>
> - "ttcp%s: %d I/O calls, msec/call = %.2f, calls/sec = %.2f\n",<br>
> + "ttcp%s: %ld I/O calls, msec/call = %.2f, calls/sec = %.2f\n",<br>
> trans?"-t":"-r",<br>
> numCalls,<br>
> 1024.0 * realt/((double)numCalls),<br>
> @@ -431,7 +467,7 @@ char **argv;<br>
> fprintf(stdout,"ttcp%s: %s\n", trans?"-t":"-r", stats);<br>
> if (verbose) {<br>
> fprintf(stdout,<br>
> - "ttcp%s: buffer address %#x\n",<br>
> + "ttcp%s: buffer address %p\n",<br>
> trans?"-t":"-r",<br>
> buf);<br>
> }<br>
> @@ -440,6 +476,7 @@ char **argv;<br>
> usage:<br>
> fprintf(stderr,Usage);<br>
> exit(1);<br>
> + return 0;<br>
> }<br>
><br>
> void<br>
> @@ -459,7 +496,7 @@ char *s;<br>
> fprintf(stderr,"ttcp%s: %s\n", trans?"-t":"-r", s);<br>
> }<br>
><br>
> -pattern( cp, cnt )<br>
> +void pattern( cp, cnt )<br>
> register char *cp;<br>
> register int cnt;<br>
> {<br>
> @@ -554,6 +591,7 @@ prep_timer()<br>
> double<br>
> read_timer(str,len)<br>
> char *str;<br>
> +int len;<br>
> {<br>
> struct timeval timedol;<br>
> struct rusage ru1;<br>
> @@ -614,13 +652,13 @@ prusage(r0, r1, e, b, outp)<br>
><br>
> case 'U':<br>
> tvsub(&tdiff, &r1->ru_utime, &r0->ru_utime);<br>
> - sprintf(outp,"%d.%01d", tdiff.tv_sec, tdiff.tv_usec/100000);<br>
> + sprintf(outp,"%ld.%01ld", tdiff.tv_sec, tdiff.tv_usec/100000);<br>
> END(outp);<br>
> break;<br>
><br>
> case 'S':<br>
> tvsub(&tdiff, &r1->ru_stime, &r0->ru_stime);<br>
> - sprintf(outp,"%d.%01d", tdiff.tv_sec, tdiff.tv_usec/100000);<br>
> + sprintf(outp,"%ld.%01ld", tdiff.tv_sec, tdiff.tv_usec/100000);<br>
> END(outp);<br>
> break;<br>
><br>
> @@ -642,18 +680,18 @@ prusage(r0, r1, e, b, outp)<br>
> break;<br>
><br>
> case 'X':<br>
> - sprintf(outp,"%d", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t);<br>
> + sprintf(outp,"%ld", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t);<br>
> END(outp);<br>
> break;<br>
><br>
> case 'D':<br>
> - sprintf(outp,"%d", t == 0 ? 0 :<br>
> + sprintf(outp,"%ld", t == 0 ? 0 :<br>
> (r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t);<br>
> END(outp);<br>
> break;<br>
><br>
> case 'K':<br>
> - sprintf(outp,"%d", t == 0 ? 0 :<br>
> + sprintf(outp,"%ld", t == 0 ? 0 :<br>
> ((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) -<br>
> (r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t);<br>
> END(outp);<br>
> @@ -743,16 +781,16 @@ register char *cp;<br>
> /*<br>
> * N R E A D<br>
> */<br>
> -Nread( fd, buf, count )<br>
> +int Nread( fd, buf, count )<br>
> int fd;<br>
> void *buf;<br>
> int count;<br>
> {<br>
> struct sockaddr_in from;<br>
> - int len = sizeof(from);<br>
> + socklen_t len = sizeof(from);<br>
> register int cnt;<br>
> if( udp ) {<br>
> - cnt = recvfrom( fd, buf, count, 0, &from, &len );<br>
> + cnt = recvfrom( fd, buf, count, 0, (struct sockaddr *)&from, &len );<br>
> numCalls++;<br>
> } else {<br>
> if( b_flag )<br>
> @@ -774,7 +812,7 @@ int count;<br>
> /*<br>
> * N W R I T E<br>
> */<br>
> -Nwrite( fd, buf, count )<br>
> +int Nwrite( fd, buf, count )<br>
> int fd;<br>
> void *buf;<br>
> int count;<br>
> @@ -782,9 +820,10 @@ int count;<br>
> register int cnt;<br>
> if( udp ) {<br>
> again:<br>
> - cnt = sendto( fd, buf, count, 0, &sinhim, sizeof(sinhim) );<br>
> + cnt = sendto( fd, buf, count, 0, sinhim_p, sizeof(sinhim) );<br>
> numCalls++;<br>
> if( cnt<0 && errno == ENOBUFS ) {<br>
> + printf("ttcp: out of buffers -- delaying\n"); /*JRS*/<br>
> delay(18000);<br>
> errno = 0;<br>
> goto again;<br>
> @@ -797,13 +836,13 @@ again:<br>
> }<br>
><br>
> void<br>
> -delay(us)<br>
> +delay(int us)<br>
> {<br>
> struct timeval tv;<br>
><br>
> tv.tv_sec = 0;<br>
> tv.tv_usec = us;<br>
> - (void)select( 1, (char *)0, (char *)0, (char *)0, &tv );<br>
> + (void)select( 1, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv );<br>
> }<br>
><br>
> /*<br>
> --<br>
> 2.27.0<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank" rel="noreferrer">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank" rel="noreferrer">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div></div>