Skip to content

Commit

Permalink
lib-http: test-http-payload: server: Fix asynchronous listening.
Browse files Browse the repository at this point in the history
The listening socket was blocking and the io handler only accepted one connection per run.
  • Loading branch information
stephanbosch authored and villesavolainen committed Feb 6, 2019
1 parent f1bbf3b commit 8df31c7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/lib-http/test-http-payload.c
Expand Up @@ -588,15 +588,18 @@ static void client_accept(void *context ATTR_UNUSED)
{
int fd;

/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
if (fd == -1)
return;
if (fd == -2) {
i_fatal("test server: accept() failed: %m");
}
for (;;) {
/* accept new client */
if ((fd=net_accept(fd_listen, NULL, NULL)) < 0) {
if (errno == EAGAIN)
break;
if (errno == ECONNABORTED)
continue;
i_fatal("test server: accept() failed: %m");
}

client_init(fd);
client_init(fd);
}
}

/* */
Expand Down Expand Up @@ -1294,6 +1297,7 @@ static void test_open_server_fd(void)
i_fatal("listen(%s:%u) failed: %m",
net_ip2addr(&bind_ip), bind_port);
}
net_set_nonblock(fd_listen, TRUE);
}

static void test_server_kill(void)
Expand Down

0 comments on commit 8df31c7

Please sign in to comment.