apps/examples/udpblaster: Add option to use poll() on output (only). Also picks up some fixes to various typographical errors.
This commit is contained in:
parent
93f84dcc8f
commit
c5edf40542
@ -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
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* 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"
|
||||
|
@ -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 <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -39,7 +39,10 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -72,7 +72,7 @@
|
||||
* pstate - Abstracts the underlying session.
|
||||
*
|
||||
* Returned Values:
|
||||
* EXIT_SUCESS only
|
||||
* EXIT_SUCCESS only
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user