From 635db4895afd9475f2bc526a94b455a8ffa27d2f Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Fri, 15 Feb 2019 09:53:48 +0000 Subject: [PATCH] socket-tcp-skip-in-flight: Don't fail on EAGAIN The server socket is marked as nonblocking, and if the client doesn't connect, accept() will fail and set errno to EAGAIN (or EWOULDBLOCK). Instead, use poll to wait for POLLIN event on the file descriptor. Suggested-by: Andrei Vagin Signed-off-by: Radostin Stoyanov --- test/zdtm/static/socket-tcp-skip-in-flight.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/zdtm/static/socket-tcp-skip-in-flight.c b/test/zdtm/static/socket-tcp-skip-in-flight.c index 8805e7d1a..a26900a7d 100644 --- a/test/zdtm/static/socket-tcp-skip-in-flight.c +++ b/test/zdtm/static/socket-tcp-skip-in-flight.c @@ -1,3 +1,4 @@ +#include #include "zdtmtst.h" #ifdef ZDTM_IPV4V6 @@ -26,9 +27,11 @@ const char *test_author = "Radostin Stoyanov "; int main(int argc, char **argv) { + struct pollfd poll_set[1]; int port = 9990; int fd_s, fd_c, fd; int flags; + int ret; test_init(argc, argv); @@ -64,12 +67,20 @@ int main(int argc, char **argv) return -1; } + memset(poll_set, '\0', sizeof(poll_set)); + poll_set[0].fd = fd_s; + poll_set[0].events = POLLIN; + ret = poll(poll_set, 1, -1); + if (ret < 0) { + pr_perror("poll() failed"); + return 1; + } + fd = tcp_accept_server(fd_s); if (fd < 0) { fail("Unable to accept a new connection"); return 1; } - close(fd); close(fd_c);