Client addresses with option fork now apply option max-children
diff --git a/CHANGES b/CHANGES
index 1f3f346..cdf4cb1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -206,6 +206,10 @@
Fixed option sourceport with UDP6-DATAGRAM.
+ Some client addresses (e.g. TCP-CONNECT) take the fork option for
+ automatically spawning new connections, however the max-children option
+ was not applied.
+
Coding:
Introduced groups_t instead of uint32_t, for more flexibility.
diff --git a/xio-ipapp.c b/xio-ipapp.c
index 1487168..d8b2581 100644
--- a/xio-ipapp.c
+++ b/xio-ipapp.c
@@ -36,6 +36,7 @@
int pf = addrdesc->arg3;
const char *hostname = argv[1], *portname = argv[2];
bool dofork = false;
+ int maxchildren = 0;
union sockaddr_union us_sa, *us = &us_sa;
socklen_t uslen = sizeof(us_sa);
struct addrinfo *themlist, *themp;
@@ -60,6 +61,20 @@
applyopts(sfd, -1, opts, PH_INIT);
retropt_bool(opts, OPT_FORK, &dofork);
+ if (dofork) {
+ if (!(xioflags & XIO_MAYFORK)) {
+ Error("option fork not allowed here");
+ return STAT_NORETRY;
+ }
+ sfd->flags |= XIO_DOESFORK;
+ }
+
+ retropt_int(opts, OPT_MAX_CHILDREN, &maxchildren);
+
+ if (! dofork && maxchildren) {
+ Error("option max-children not allowed without option fork");
+ return STAT_NORETRY;
+ }
if (_xioopen_ipapp_prepare(opts, &opts0, hostname, portname, &pf, ipproto,
sfd->para.socket.ip.ai_flags,
@@ -169,6 +184,10 @@
Close(sfd->fd);
/* with and without retry */
Nanosleep(&sfd->intervall, NULL);
+ while (maxchildren > 0 && num_child >= maxchildren) {
+ Info1("all %d allowed children are active, waiting", maxchildren);
+ Nanosleep(&sfd->intervall, NULL);
+ }
dropopts(opts, PH_ALL); free(opts); opts = copyopts(opts0, GROUP_ALL);
continue; /* with next socket() bind() connect() */
} else
diff --git a/xio-listen.c b/xio-listen.c
index 2e99833..28b9f42 100644
--- a/xio-listen.c
+++ b/xio-listen.c
@@ -190,7 +190,6 @@
int result;
retropt_bool(opts, OPT_FORK, &dofork);
-
if (dofork) {
if (!(xioflags & XIO_MAYFORK)) {
Error("option fork not allowed here");