From: Fredrik Tolf Date: Mon, 12 May 2025 15:59:39 +0000 (+0200) Subject: call[fs]cgi: At least for now, simply block when connecting to handler. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=8bff711bd88d36c8600bfd7504b47a6c56a1d3f6;p=ashd.git call[fs]cgi: At least for now, simply block when connecting to handler. It's not optimal, but the naive mtio implementation has the thundering-herd problem, and this also creates a natural choke-point, transmitting the request buffering responsibility to the parent handler where it belongs. The more ideal solution would probably be to let running requests continue being handled while serializing receving incoming requests and connecting to the request handler. --- diff --git a/src/callfcgi.c b/src/callfcgi.c index 83a6c7c..8ff0eff 100644 --- a/src/callfcgi.c +++ b/src/callfcgi.c @@ -246,27 +246,14 @@ static void startnolisten(void) static int sconnect(void) { int fd; - int err; - socklen_t errlen; fd = socket(cafamily, SOCK_STREAM, 0); - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); - while(1) { - if(connect(fd, curaddr, caddrlen)) { - if((errno == EINPROGRESS) || (errno == EAGAIN)) { - block(fd, EV_WRITE, 30); - errlen = sizeof(err); - if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) || ((errno = err) != 0)) { - close(fd); - return(-1); - } - return(fd); - } - close(fd); - return(-1); - } - return(fd); + if(connect(fd, curaddr, caddrlen)) { + close(fd); + return(-1); } + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + return(fd); } static int econnect(void) diff --git a/src/callscgi.c b/src/callscgi.c index 60c72ac..ee46ac1 100644 --- a/src/callscgi.c +++ b/src/callscgi.c @@ -233,27 +233,14 @@ static void startnolisten(void) static int sconnect(void) { int fd; - int err; - socklen_t errlen; fd = socket(cafamily, SOCK_STREAM, 0); - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); - while(1) { - if(connect(fd, curaddr, caddrlen)) { - if((errno == EINPROGRESS) || (errno == EAGAIN)) { - block(fd, EV_WRITE, 30); - errlen = sizeof(err); - if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) || ((errno = err) != 0)) { - close(fd); - return(-1); - } - return(fd); - } - close(fd); - return(-1); - } - return(fd); + if(connect(fd, curaddr, caddrlen)) { + close(fd); + return(-1); } + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + return(fd); } static int econnect(void)