Keep FastCGI available during restarts

This commit is contained in:
udo
2026-07-16 22:00:08 +00:00
parent 93c701c6c7
commit caffb3f404
16 changed files with 192 additions and 41 deletions
+16 -2
View File
@@ -206,7 +206,6 @@ FastCGIServer::shutdown()
{
printf("Closing server socket %i\n", *it);
close(*it);
sleep(1);
}
for (std::vector<std::string>::iterator it = listen_unlink.begin();
@@ -223,7 +222,6 @@ FastCGIServer::shutdown()
delete it->second;
}
sleep(1);
server_sockets.clear();
}
@@ -264,6 +262,22 @@ FastCGIServer::listen(unsigned tcp_port)
return(listen(tcp_port, "0.0.0.0"));
}
int
FastCGIServer::adopt_listener(int socket_handle, char type)
{
int accepting = 0;
socklen_t accepting_size = sizeof(accepting);
if(socket_handle < 0 || getsockopt(socket_handle, SOL_SOCKET, SO_ACCEPTCONN,
&accepting, &accepting_size) != 0 || !accepting)
throw std::runtime_error("inherited descriptor is not a listening socket");
set_socket_nonblocking(socket_handle);
server_sockets.push_back(socket_handle);
server_socket_types[socket_handle] = type;
printf("(P) adopted #%i inherited %s listener\n", socket_handle,
type == 'F' ? "FastCGI" : "server");
return(socket_handle);
}
int
FastCGIServer::listen(unsigned tcp_port, const std::string& bind_address)
{
+1
View File
@@ -57,6 +57,7 @@ public:
int listen_http(unsigned tcp_port, const std::string& bind_address);
int listen_cli(const std::string& local_path);
int listen(const std::string& local_path);
int adopt_listener(int socket_handle, char type = 'F');
void process(int timeout_ms = -1); // timeout_ms<0 blocks forever
void process_forever();