Re: [PATCH v1 2/4] rtemsbsd:Updated TTCP code with network demo code

2021-06-08 Thread Joel Sherrill
On Tue, Jun 8, 2021, 12:12 PM Gedare Bloom  wrote:

> Are these updates from OAR? Do you want to scope them with #ifdef
> #endif for RTEMS? Or this is clone-and-own software now?
>

Yes. The code is old a s has warnings which need to be fixed.

Because this program gets compiled natively when running benchmarks. It
takes a Tx and Rx side to run. One is on your host.

I have no idea how to mark things like this

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.

>
> Why not import from network-demos?


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.

--joel

>
>
> On Tue, Jun 8, 2021 at 10:12 AM Stephen Clark 
> wrote:
> >
> > Updated the TTCP code to match the ttcp.c in RTEMS network-demos
> > repository (https://git.rtems.org/network-demos/).
> > ---
> >  rtemsbsd/ttcp/ttcp.c | 91 +++-
> >  1 file changed, 65 insertions(+), 26 deletions(-)
> >
> > diff --git a/rtemsbsd/ttcp/ttcp.c b/rtemsbsd/ttcp/ttcp.c
> > index 305a7c7d..dc62c64b 100644
> > --- a/rtemsbsd/ttcp/ttcp.c
> > +++ b/rtemsbsd/ttcp/ttcp.c
> > @@ -35,8 +35,9 @@
> >   * Distribution Status -
> >   *  Public Domain.  Distribution Unlimited.
> >   */
> > +
> >  #ifndef lint
> > -static char RCSid[] = "ttcp.c $Revision$";
> > +/* static char RCSid[] = "ttcp.c $Revision$"; */
> >  #endif
> >
> >  #define BSD43
> > @@ -44,6 +45,8 @@ static char RCSid[] = "ttcp.c $Revision$";
> >  /* #define BSD41a */
> >  /* #define SYSV */ /* required on SGI IRIX releases before 3.3 */
> >
> > +#define ENABLE_NANOSLEEP_DELAY
> > +
> >  #include 
> >  #include 
> >  #include 
> > @@ -54,8 +57,12 @@ static char RCSid[] = "ttcp.c $Revision$";
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include   /* struct timeval */
> >
> > +#include 
> > +#include 
> > +
> >  #if defined(SYSV)
> >  #include 
> >  #include 
> > @@ -71,7 +78,13 @@ struct sockaddr_in sinme;
> >  struct sockaddr_in sinhim;
> >  struct sockaddr_in frominet;
> >
> > -int domain, fromlen;
> > +/* these make it easier to avoid warnings */
> > +struct sockaddr *sinhim_p = (struct sockaddr *) 
> > +struct sockaddr *sinme_p = (struct sockaddr *) 
> > +struct sockaddr *frominet_p = (struct sockaddr *) 
> > +
> > +int domain;
> > +socklen_t fromlen;
> >  int fd;/* fd of network socket */
> >
> >  int buflen = 8 * 1024; /* length of buffer */
> > @@ -97,6 +110,7 @@ char fmt = 'K';  /* output
> format: k = kilobits, K = kilobytes,
> >  *  m = megabits, M = megabytes,
> >  *  g = gigabits, G = gigabytes */
> >  int touchdata = 0; /* access data after reading */
> > +long milliseconds = 0;  /* delay in milliseconds */
> >
> >  struct hostent *addr;
> >  extern int errno;
> > @@ -124,6 +138,7 @@ Options specific to -t:\n\
> >  Options specific to -r:\n\
> > -B  for -s, only output full blocks as specified by -l (for
> TAR)\n\
> > -T  \"touch\": access each byte as it's read\n\
> > +   -m ##   delay for specified milliseconds between each write\n\
> >  ";
> >
> >  char stats[128];
> > @@ -133,7 +148,7 @@ double cput, realt; /* user, real time
> (seconds) */
> >
> >  void err();
> >  void mes();
> > -int pattern();
> > +void pattern();
> >  void prep_timer();
> >  double read_timer();
> >  int Nread();
> > @@ -147,7 +162,18 @@ sigpipe()
> >  {
> >  }
> >
> > -main(argc,argv)
> > +void millisleep(long msec)
> > +{
> > +#if defined(ENABLE_NANOSLEEP_DELAY)
> > +  struct timespec req;
> > +
> > +  req.tv_sec = msec / 1000;
> > +  req.tv_nsec = (msec % 1000) * 100;
> > +
> > +  nanosleep( , NULL );
> > +#endif
> > +}
> > +int main(argc,argv)
> >  int argc;
> >  char **argv;
> >  {
> > @@ -156,7 +182,7 @@ char **argv;
> >
> > if (argc < 2) goto usage;
> >
> > -   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:")) !=
> -1) {
> > +   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:m:n:p:A:O:")) !=
> -1) {
> > switch (c) {
> >
> > case 'B':
> > @@ -179,6 +205,12 @@ char **argv;
> > "ttcp: -D option ignored: TCP_NODELAY socket option not
> supported\n");
> >  #endif
> > break;
> > +   case 'm':
> > +   milliseconds = atoi(optarg);
> > +   #if !defined(ENABLE_NANOSLEEP_DELAY)
> > +   fprintf(stderr, "millisecond delay
> disabled\n");
> > +   #endif
> > +   break;
> > case 'n':
> > nbuf = atoi(optarg);
> > break;
> > @@ -285,7 +317,7 @@ char **argv;
> > err("socket");
> > mes("socket");
> >
> > -   if (bind(fd, , sizeof(sinme)) < 

Re: [PATCH v1 2/4] rtemsbsd:Updated TTCP code with network demo code

2021-06-08 Thread Gedare Bloom
Are these updates from OAR? Do you want to scope them with #ifdef
#endif for RTEMS? Or this is clone-and-own software now?

Why not import from network-demos?


On Tue, Jun 8, 2021 at 10:12 AM Stephen Clark  wrote:
>
> Updated the TTCP code to match the ttcp.c in RTEMS network-demos
> repository (https://git.rtems.org/network-demos/).
> ---
>  rtemsbsd/ttcp/ttcp.c | 91 +++-
>  1 file changed, 65 insertions(+), 26 deletions(-)
>
> diff --git a/rtemsbsd/ttcp/ttcp.c b/rtemsbsd/ttcp/ttcp.c
> index 305a7c7d..dc62c64b 100644
> --- a/rtemsbsd/ttcp/ttcp.c
> +++ b/rtemsbsd/ttcp/ttcp.c
> @@ -35,8 +35,9 @@
>   * Distribution Status -
>   *  Public Domain.  Distribution Unlimited.
>   */
> +
>  #ifndef lint
> -static char RCSid[] = "ttcp.c $Revision$";
> +/* static char RCSid[] = "ttcp.c $Revision$"; */
>  #endif
>
>  #define BSD43
> @@ -44,6 +45,8 @@ static char RCSid[] = "ttcp.c $Revision$";
>  /* #define BSD41a */
>  /* #define SYSV */ /* required on SGI IRIX releases before 3.3 */
>
> +#define ENABLE_NANOSLEEP_DELAY
> +
>  #include 
>  #include 
>  #include 
> @@ -54,8 +57,12 @@ static char RCSid[] = "ttcp.c $Revision$";
>  #include 
>  #include 
>  #include 
> +#include 
>  #include   /* struct timeval */
>
> +#include 
> +#include 
> +
>  #if defined(SYSV)
>  #include 
>  #include 
> @@ -71,7 +78,13 @@ struct sockaddr_in sinme;
>  struct sockaddr_in sinhim;
>  struct sockaddr_in frominet;
>
> -int domain, fromlen;
> +/* these make it easier to avoid warnings */
> +struct sockaddr *sinhim_p = (struct sockaddr *) 
> +struct sockaddr *sinme_p = (struct sockaddr *) 
> +struct sockaddr *frominet_p = (struct sockaddr *) 
> +
> +int domain;
> +socklen_t fromlen;
>  int fd;/* fd of network socket */
>
>  int buflen = 8 * 1024; /* length of buffer */
> @@ -97,6 +110,7 @@ char fmt = 'K';  /* output format: k = 
> kilobits, K = kilobytes,
>  *  m = megabits, M = megabytes,
>  *  g = gigabits, G = gigabytes */
>  int touchdata = 0; /* access data after reading */
> +long milliseconds = 0;  /* delay in milliseconds */
>
>  struct hostent *addr;
>  extern int errno;
> @@ -124,6 +138,7 @@ Options specific to -t:\n\
>  Options specific to -r:\n\
> -B  for -s, only output full blocks as specified by -l (for 
> TAR)\n\
> -T  \"touch\": access each byte as it's read\n\
> +   -m ##   delay for specified milliseconds between each write\n\
>  ";
>
>  char stats[128];
> @@ -133,7 +148,7 @@ double cput, realt; /* user, real time (seconds) 
> */
>
>  void err();
>  void mes();
> -int pattern();
> +void pattern();
>  void prep_timer();
>  double read_timer();
>  int Nread();
> @@ -147,7 +162,18 @@ sigpipe()
>  {
>  }
>
> -main(argc,argv)
> +void millisleep(long msec)
> +{
> +#if defined(ENABLE_NANOSLEEP_DELAY)
> +  struct timespec req;
> +
> +  req.tv_sec = msec / 1000;
> +  req.tv_nsec = (msec % 1000) * 100;
> +
> +  nanosleep( , NULL );
> +#endif
> +}
> +int main(argc,argv)
>  int argc;
>  char **argv;
>  {
> @@ -156,7 +182,7 @@ char **argv;
>
> if (argc < 2) goto usage;
>
> -   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:")) != -1) {
> +   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:m:n:p:A:O:")) != -1) {
> switch (c) {
>
> case 'B':
> @@ -179,6 +205,12 @@ char **argv;
> "ttcp: -D option ignored: TCP_NODELAY socket option not supported\n");
>  #endif
> break;
> +   case 'm':
> +   milliseconds = atoi(optarg);
> +   #if !defined(ENABLE_NANOSLEEP_DELAY)
> +   fprintf(stderr, "millisecond delay 
> disabled\n");
> +   #endif
> +   break;
> case 'n':
> nbuf = atoi(optarg);
> break;
> @@ -285,7 +317,7 @@ char **argv;
> err("socket");
> mes("socket");
>
> -   if (bind(fd, , sizeof(sinme)) < 0)
> +   if (bind(fd, sinme_p, sizeof(sinme)) < 0)
> err("bind");
>
>  #if defined(SO_SNDBUF) || defined(SO_RCVBUF)
> @@ -305,7 +337,9 @@ char **argv;
>  #endif
>
> if (!udp)  {
> +#if !defined(__rtems__)
> signal(SIGPIPE, sigpipe);
> +#endif
> if (trans) {
> /* We are the client if transmitting */
> if (options)  {
> @@ -326,7 +360,7 @@ char **argv;
> mes("nodelay");
> }
>  #endif
> -   if(connect(fd, , sizeof(sinhim) ) < 0)
> +   if(connect(fd, sinhim_p, sizeof(sinhim) ) < 0)
> err("connect");
> mes("connect");
> } else {
> @@ -348,11 +382,11 @@ char **argv;
> }
> fromlen = 

[PATCH v1 2/4] rtemsbsd:Updated TTCP code with network demo code

2021-06-08 Thread Stephen Clark
Updated the TTCP code to match the ttcp.c in RTEMS network-demos
repository (https://git.rtems.org/network-demos/).
---
 rtemsbsd/ttcp/ttcp.c | 91 +++-
 1 file changed, 65 insertions(+), 26 deletions(-)

diff --git a/rtemsbsd/ttcp/ttcp.c b/rtemsbsd/ttcp/ttcp.c
index 305a7c7d..dc62c64b 100644
--- a/rtemsbsd/ttcp/ttcp.c
+++ b/rtemsbsd/ttcp/ttcp.c
@@ -35,8 +35,9 @@
  * Distribution Status -
  *  Public Domain.  Distribution Unlimited.
  */
+
 #ifndef lint
-static char RCSid[] = "ttcp.c $Revision$";
+/* static char RCSid[] = "ttcp.c $Revision$"; */
 #endif
 
 #define BSD43
@@ -44,6 +45,8 @@ static char RCSid[] = "ttcp.c $Revision$";
 /* #define BSD41a */
 /* #define SYSV */ /* required on SGI IRIX releases before 3.3 */
 
+#define ENABLE_NANOSLEEP_DELAY
+
 #include 
 #include 
 #include 
@@ -54,8 +57,12 @@ static char RCSid[] = "ttcp.c $Revision$";
 #include 
 #include 
 #include 
+#include 
 #include   /* struct timeval */
 
+#include 
+#include 
+
 #if defined(SYSV)
 #include 
 #include 
@@ -71,7 +78,13 @@ struct sockaddr_in sinme;
 struct sockaddr_in sinhim;
 struct sockaddr_in frominet;
 
-int domain, fromlen;
+/* these make it easier to avoid warnings */
+struct sockaddr *sinhim_p = (struct sockaddr *) 
+struct sockaddr *sinme_p = (struct sockaddr *) 
+struct sockaddr *frominet_p = (struct sockaddr *) 
+
+int domain;
+socklen_t fromlen;
 int fd;/* fd of network socket */
 
 int buflen = 8 * 1024; /* length of buffer */
@@ -97,6 +110,7 @@ char fmt = 'K';  /* output format: k = 
kilobits, K = kilobytes,
 *  m = megabits, M = megabytes, 
 *  g = gigabits, G = gigabytes */
 int touchdata = 0; /* access data after reading */
+long milliseconds = 0;  /* delay in milliseconds */
 
 struct hostent *addr;
 extern int errno;
@@ -124,6 +138,7 @@ Options specific to -t:\n\
 Options specific to -r:\n\
-B  for -s, only output full blocks as specified by -l (for TAR)\n\
-T  \"touch\": access each byte as it's read\n\
+   -m ##   delay for specified milliseconds between each write\n\
 "; 
 
 char stats[128];
@@ -133,7 +148,7 @@ double cput, realt; /* user, real time (seconds) */
 
 void err();
 void mes();
-int pattern();
+void pattern();
 void prep_timer();
 double read_timer();
 int Nread();
@@ -147,7 +162,18 @@ sigpipe()
 {
 }
 
-main(argc,argv)
+void millisleep(long msec)
+{
+#if defined(ENABLE_NANOSLEEP_DELAY)
+  struct timespec req;
+
+  req.tv_sec = msec / 1000;
+  req.tv_nsec = (msec % 1000) * 100;
+
+  nanosleep( , NULL );
+#endif
+}
+int main(argc,argv)
 int argc;
 char **argv;
 {
@@ -156,7 +182,7 @@ char **argv;
 
if (argc < 2) goto usage;
 
-   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:n:p:A:O:")) != -1) {
+   while ((c = getopt(argc, argv, "drstuvBDTb:f:l:m:n:p:A:O:")) != -1) {
switch (c) {
 
case 'B':
@@ -179,6 +205,12 @@ char **argv;
"ttcp: -D option ignored: TCP_NODELAY socket option not supported\n");
 #endif
break;
+   case 'm':
+   milliseconds = atoi(optarg);
+   #if !defined(ENABLE_NANOSLEEP_DELAY)
+   fprintf(stderr, "millisecond delay disabled\n");
+   #endif
+   break;
case 'n':
nbuf = atoi(optarg);
break;
@@ -285,7 +317,7 @@ char **argv;
err("socket");
mes("socket");
 
-   if (bind(fd, , sizeof(sinme)) < 0)
+   if (bind(fd, sinme_p, sizeof(sinme)) < 0)
err("bind");
 
 #if defined(SO_SNDBUF) || defined(SO_RCVBUF)
@@ -305,7 +337,9 @@ char **argv;
 #endif
 
if (!udp)  {
+#if !defined(__rtems__)
signal(SIGPIPE, sigpipe);
+#endif
if (trans) {
/* We are the client if transmitting */
if (options)  {
@@ -326,7 +360,7 @@ char **argv;
mes("nodelay");
}
 #endif
-   if(connect(fd, , sizeof(sinhim) ) < 0)
+   if(connect(fd, sinhim_p, sizeof(sinhim) ) < 0)
err("connect");
mes("connect");
} else {
@@ -348,11 +382,11 @@ char **argv;
}
fromlen = sizeof(frominet);
domain = AF_INET;
-   if((fd=accept(fd, , ) ) < 0)
+   if((fd=accept(fd, frominet_p, ) ) < 0)
err("accept");
{ struct sockaddr_in peer;
- int peerlen = sizeof(peer);
- if (getpeername(fd, (struct sockaddr_in *) , 
+ socklen_t peerlen = sizeof(peer);
+ if (getpeername(fd, (struct sockaddr *) , 
) < 0) {