mirror of
https://repo.or.cz/socat.git
synced 2025-01-22 02:44:09 +00:00
Client addresses with option fork now apply option max-children
This commit is contained in:
parent
c00262b42d
commit
e610b14470
3 changed files with 23 additions and 1 deletions
4
CHANGES
4
CHANGES
|
@ -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.
|
||||||
|
|
||||||
|
|
19
xio-ipapp.c
19
xio-ipapp.c
|
@ -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
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue