From c5edf40542ff5445821d742e26221b51f384047c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Sep 2018 06:59:23 -0600 Subject: [PATCH] apps/examples/udpblaster: Add option to use poll() on output (only). Also picks up some fixes to various typographical errors. --- examples/udpblaster/Kconfig | 10 ++++ examples/udpblaster/udpblaster.h | 24 ++++----- examples/udpblaster/udpblaster_target.c | 50 ++++++++++++++++--- .../traveler/tools/libwld/wld_loadpaltable.c | 2 +- nshlib/nsh_session.c | 2 +- nshlib/nsh_stdsession.c | 2 +- system/hex2bin/hex2bin_main.c | 2 +- system/hex2bin/hex2mem_main.c | 2 +- 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/examples/udpblaster/Kconfig b/examples/udpblaster/Kconfig index 61516baed..1ce058629 100644 --- a/examples/udpblaster/Kconfig +++ b/examples/udpblaster/Kconfig @@ -28,6 +28,16 @@ config EXAMPLES_UDPBLASTER_PRIORITY int "Nettest priority" default 100 +config EXAMPLES_UDPBLASTER_POLLOUT + bool "Use poll() to pace output" + default n + depends on !DISABLE_POLL + ---help--- + Client will use poll() to verify that sendto() will not block. This + does not improve performance (in fact, it will degrade perform + slightly). But it is useful for verifying that poll() can be used + to pace output. + config EXAMPLES_UDPBLASTER_HOSTRATE int "Host send rate (bits/second)" default 800000 diff --git a/examples/udpblaster/udpblaster.h b/examples/udpblaster/udpblaster.h index 0f8736b12..11eddd71d 100644 --- a/examples/udpblaster/udpblaster.h +++ b/examples/udpblaster/udpblaster.h @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udpblaster/udpblaster.h * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -88,28 +88,28 @@ #define UDP_HDRLEN 8 /* Size of UDP header */ #if defined(CONFIG_NET_ETHERNET) -# define UDPBLASTER_MTU CONFIG_NET_ETH_MTU +# define UDPBLASTER_PKTSIZE CONFIG_NET_ETH_PKTSIZE # ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv6 -# define UDPBLASTER_MSS (UDPBLASTER_MTU - ETH_HDRLEN - IPv6_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - ETH_HDRLEN - IPv6_HDRLEN - UDP_HDRLEN) # else -# define UDPBLASTER_MSS (UDPBLASTER_MTU - ETH_HDRLEN - IPv4_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - ETH_HDRLEN - IPv4_HDRLEN - UDP_HDRLEN) # endif #elif defined(CONFIG_NET_LOOPBACK) -# define UDPBLASTER_MTU 1518 +# define UDPBLASTER_PKTSIZE 1518 # ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv6 -# define UDPBLASTER_MSS (UDPBLASTER_MTU - IPv6_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - IPv6_HDRLEN - UDP_HDRLEN) # else -# define UDPBLASTER_MSS (UDPBLASTER_MTU - IPv4_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - IPv4_HDRLEN - UDP_HDRLEN) # endif #elif defined(CONFIG_NET_6LOWPAN) -# define UDPBLASTER_MTU CONFIG_NET_6LOWPAN_PKTSIZE -# define UDPBLASTER_MSS (CONFIG_NET_6LOWPAN_PKTSIZE - IPv6_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_PKTSIZE CONFIG_NET_6LOWPAN_PKTSIZE +# define UDPBLASTER_MSS (CONFIG_NET_6LOWPAN_PKTSIZE - IPv6_HDRLEN - UDP_HDRLEN) #elif defined(CONFIG_NET_SLIP) -# define UDPBLASTER_MTU CONFIG_NET_SLIP_MTU +# define UDPBLASTER_PKTSIZE CONFIG_NET_SLIP_PKTSIZE # ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv6 -# define UDPBLASTER_MSS (UDPBLASTER_MTU - IPv6_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - IPv6_HDRLEN - UDP_HDRLEN) # else -# define UDPBLASTER_MSS (UDPBLASTER_MTU - IPv4_HDRLEN - UDP_HDRLEN) +# define UDPBLASTER_MSS (UDPBLASTER_PKTSIZE - IPv4_HDRLEN - UDP_HDRLEN) # endif #else # error "Additional link layer definitions needed" diff --git a/examples/udpblaster/udpblaster_target.c b/examples/udpblaster/udpblaster_target.c index 82e0f71ce..2e9cfdada 100644 --- a/examples/udpblaster/udpblaster_target.c +++ b/examples/udpblaster/udpblaster_target.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/udpblaster/udpblaster_target.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,7 +39,10 @@ #include "config.h" +#include #include +#include +#include #include #include @@ -225,7 +228,8 @@ int udpblaster_main(int argc, char *argv[]) if (sockfd < 0) { fprintf(stderr, "ERROR: socket() failed: %d\n", errno); - return 1; + ret = EXIT_FAILURE; + goto errout_with_socket; } target.sin_family = AF_INET; @@ -236,7 +240,8 @@ int udpblaster_main(int argc, char *argv[]) if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0) { printf("server: ERROR bind failure: %d\n", errno); - return 1; + ret = EXIT_FAILURE; + goto errout_with_socket; } #else @@ -255,7 +260,8 @@ int udpblaster_main(int argc, char *argv[]) if (sockfd < 0) { fprintf(stderr, "ERROR: socket() failed: %d\n", errno); - return 1; + ret = EXIT_FAILURE; + goto errout_with_socket; } target.sin6_family = AF_INET6; @@ -272,8 +278,9 @@ int udpblaster_main(int argc, char *argv[]) if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0) { - printf("server: ERROR bind failure: %d\n", errno); - return 1; + printf(stderr, "ERROR bind failure: %d\n", errno); + ret = EXIT_FAILURE; + goto errout_with_socket; } #endif @@ -282,12 +289,37 @@ int udpblaster_main(int argc, char *argv[]) for (;;) { +#ifdef CONFIG_EXAMPLES_UDPBLASTER_POLLOUT + struct pollfd fds[1]; + + memset(fds, 0, 1 * sizeof(struct pollfd)); + fds[0].fd = sockfd; + fds[0].events = POLLOUT | POLLHUP; + + /* Wait until we can send data or until the connection is lost */ + + ret = poll(fds, 1, -1); + if (ret < 0) + { + printf("client: ERROR poll failed: %d\n", errno); + goto errout_with_socket; + } + + if ((fds[0].revents & POLLHUP) != 0) + { + printf("client: WARNING poll returned POLLHUP\n"); + ret = EXIT_SUCCESS; + goto errout_with_socket; + } +#endif + ret = sendto(sockfd, g_udpblaster_text, UDPBLASTER_SENDSIZE, 0, (struct sockaddr *)&host, addrlen); if (ret < 0) { fprintf(stderr, "ERROR: sendto() failed: %d\n", errno); - return 1; + ret = EXIT_FAILURE; + goto errout_with_socket; } if (++npackets >= 10) @@ -303,5 +335,7 @@ int udpblaster_main(int argc, char *argv[]) } } - return 0; /* Won't get here */ +errout_with_socket: + close(sockfd); + return ret; } diff --git a/graphics/traveler/tools/libwld/wld_loadpaltable.c b/graphics/traveler/tools/libwld/wld_loadpaltable.c index 023df31d6..152405de0 100644 --- a/graphics/traveler/tools/libwld/wld_loadpaltable.c +++ b/graphics/traveler/tools/libwld/wld_loadpaltable.c @@ -346,7 +346,7 @@ uint8_t wld_load_paltable(char *file) } fclose(fp); - return WORLD_SUCESS; + return WORLD_SUCCESS; # endif /* USE_PAL_RANGES */ #endif /* !MSWINDOWS */ } diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c index e463368ab..5d4fba7c3 100644 --- a/nshlib/nsh_session.c +++ b/nshlib/nsh_session.c @@ -74,7 +74,7 @@ * pstate - Abstracts the underlying session. * * Returned Values: - * EXIT_SUCESS or EXIT_FAILURE is returned. + * EXIT_SUCCESS or EXIT_FAILURE is returned. * ****************************************************************************/ diff --git a/nshlib/nsh_stdsession.c b/nshlib/nsh_stdsession.c index 96caad684..35c5ae15e 100644 --- a/nshlib/nsh_stdsession.c +++ b/nshlib/nsh_stdsession.c @@ -72,7 +72,7 @@ * pstate - Abstracts the underlying session. * * Returned Values: - * EXIT_SUCESS only + * EXIT_SUCCESS only * ****************************************************************************/ diff --git a/system/hex2bin/hex2bin_main.c b/system/hex2bin/hex2bin_main.c index 20d613d25..40150991e 100644 --- a/system/hex2bin/hex2bin_main.c +++ b/system/hex2bin/hex2bin_main.c @@ -105,7 +105,7 @@ static void show_usage(FAR const char *progname, int exitcode) * Standard task inputs * * Returned Value - * EXIT_SUCESS on success; EXIT_FAILURE on failure + * EXIT_SUCCESS on success; EXIT_FAILURE on failure * ****************************************************************************/ diff --git a/system/hex2bin/hex2mem_main.c b/system/hex2bin/hex2mem_main.c index 54414f0cc..0ee8a4cd6 100644 --- a/system/hex2bin/hex2mem_main.c +++ b/system/hex2bin/hex2mem_main.c @@ -100,7 +100,7 @@ static void show_usage(FAR const char *progname, int exitcode) * Standard task inputs * * Returned Value - * EXIT_SUCESS on success; EXIT_FAILURE on failure + * EXIT_SUCCESS on success; EXIT_FAILURE on failure * ****************************************************************************/