]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: test-smtp-payload: server: Fix asynchronous listening.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Mar 2018 13:14:03 +0000 (14:14 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 6 Feb 2019 08:08:17 +0000 (10:08 +0200)
The listening socket was blocking and the io handler only accepted one connection per run.

src/lib-smtp/test-smtp-payload.c

index 1d0920cb67b034936c01f50430dd415cdf7799b4..d66df4072441f2326dd8f94064a880f54241cffc 100644 (file)
@@ -419,15 +419,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);
+       }
 }
 
 /* */
@@ -752,6 +755,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)