Commit 635db489 authored by Radostin Stoyanov's avatar Radostin Stoyanov Committed by Andrei Vagin

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: 's avatarAndrei Vagin <avagin@gmail.com>
Signed-off-by: 's avatarRadostin Stoyanov <rstoyanov1@gmail.com>
parent 681c0539
#include <poll.h>
#include "zdtmtst.h" #include "zdtmtst.h"
#ifdef ZDTM_IPV4V6 #ifdef ZDTM_IPV4V6
...@@ -26,9 +27,11 @@ const char *test_author = "Radostin Stoyanov <rstoyanov1@gmail.com>"; ...@@ -26,9 +27,11 @@ const char *test_author = "Radostin Stoyanov <rstoyanov1@gmail.com>";
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct pollfd poll_set[1];
int port = 9990; int port = 9990;
int fd_s, fd_c, fd; int fd_s, fd_c, fd;
int flags; int flags;
int ret;
test_init(argc, argv); test_init(argc, argv);
...@@ -64,12 +67,20 @@ int main(int argc, char **argv) ...@@ -64,12 +67,20 @@ int main(int argc, char **argv)
return -1; 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); fd = tcp_accept_server(fd_s);
if (fd < 0) { if (fd < 0) {
fail("Unable to accept a new connection"); fail("Unable to accept a new connection");
return 1; return 1;
} }
close(fd); close(fd);
close(fd_c); close(fd_c);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment