Client addresses with option fork now apply option max-children

This commit is contained in:
Gerhard Rieger 2023-11-06 21:23:11 +01:00
parent c00262b42d
commit e610b14470
3 changed files with 23 additions and 1 deletions

View file

@ -206,6 +206,10 @@ Corrections:
Fixed option sourceport with UDP6-DATAGRAM. 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: Coding:
Introduced groups_t instead of uint32_t, for more flexibility. Introduced groups_t instead of uint32_t, for more flexibility.

View file

@ -36,6 +36,7 @@ int xioopen_ipapp_connect(
int pf = addrdesc->arg3; int pf = addrdesc->arg3;
const char *hostname = argv[1], *portname = argv[2]; const char *hostname = argv[1], *portname = argv[2];
bool dofork = false; bool dofork = false;
int maxchildren = 0;
union sockaddr_union us_sa, *us = &us_sa; union sockaddr_union us_sa, *us = &us_sa;
socklen_t uslen = sizeof(us_sa); socklen_t uslen = sizeof(us_sa);
struct addrinfo *themlist, *themp; struct addrinfo *themlist, *themp;
@ -60,6 +61,20 @@ int xioopen_ipapp_connect(
applyopts(sfd, -1, opts, PH_INIT); applyopts(sfd, -1, opts, PH_INIT);
retropt_bool(opts, OPT_FORK, &dofork); 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, if (_xioopen_ipapp_prepare(opts, &opts0, hostname, portname, &pf, ipproto,
sfd->para.socket.ip.ai_flags, sfd->para.socket.ip.ai_flags,
@ -169,6 +184,10 @@ int xioopen_ipapp_connect(
Close(sfd->fd); Close(sfd->fd);
/* with and without retry */ /* with and without retry */
Nanosleep(&sfd->intervall, NULL); 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); dropopts(opts, PH_ALL); free(opts); opts = copyopts(opts0, GROUP_ALL);
continue; /* with next socket() bind() connect() */ continue; /* with next socket() bind() connect() */
} else } else

View file

@ -190,7 +190,6 @@ int _xioopen_accept_fd(
int result; int result;
retropt_bool(opts, OPT_FORK, &dofork); retropt_bool(opts, OPT_FORK, &dofork);
if (dofork) { if (dofork) {
if (!(xioflags & XIO_MAYFORK)) { if (!(xioflags & XIO_MAYFORK)) {
Error("option fork not allowed here"); Error("option fork not allowed here");