apps/examples/tcpblaster: Add an option to use poll() to pace input or output.
This commit is contained in:
parent
c8f473c507
commit
25c2756a82
@ -35,6 +35,26 @@ config EXAMPLES_TCPBLASTER_PRIORITY1
|
||||
int "Target1 priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_TCPBLASTER_POLLOUT
|
||||
bool "Use poll() to pace output"
|
||||
default n
|
||||
depends on !DISABLE_POLL
|
||||
---help---
|
||||
Client will use poll() to verify that send() 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_TCPBLASTER_POLLIN
|
||||
bool "Use poll() to pace input"
|
||||
default n
|
||||
depends on !DISABLE_POLL
|
||||
---help---
|
||||
Client will use poll() to verify that recv() 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 input.
|
||||
|
||||
config EXAMPLES_TCPBLASTER_LOOPBACK
|
||||
bool "Loopback test"
|
||||
default n
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
@ -147,6 +148,30 @@ void tcpblaster_client(void)
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_TCPBLASTER_POLLOUT
|
||||
struct pollfd fds[1];
|
||||
int ret;
|
||||
|
||||
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");
|
||||
goto errout_with_socket;
|
||||
}
|
||||
#endif
|
||||
|
||||
nbytessent = send(sockfd, outbuf, SENDSIZE, 0);
|
||||
if (nbytessent < 0)
|
||||
{
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@ -187,6 +188,30 @@ void tcpblaster_server(void)
|
||||
|
||||
for (; ; )
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_TCPBLASTER_POLLIN
|
||||
struct pollfd fds[1];
|
||||
int ret;
|
||||
|
||||
memset(fds, 0, 1 * sizeof(struct pollfd));
|
||||
fds[0].fd = acceptsd;
|
||||
fds[0].events = POLLIN | POLLHUP;
|
||||
|
||||
/* Wait until we can receive data or until the connection is lost */
|
||||
|
||||
ret = poll(fds, 1, -1);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("server: ERROR poll failed: %d\n", errno);
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
|
||||
if ((fds[0].revents & POLLHUP) != 0)
|
||||
{
|
||||
printf("server: WARNING poll returned POLLHUP\n");
|
||||
goto errout_with_acceptsd;
|
||||
}
|
||||
#endif
|
||||
|
||||
nbytesread = recv(acceptsd, buffer, SENDSIZE, 0);
|
||||
if (nbytesread < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user