I'm not sure how far this is possible in practice.
Connections can be closed or broken for several reasons and with several different close/shutdown sequences.
I don't know what browsers do when you close a tab, or when you hit reload, and I don't know if this is the same for all browsers.
It's maybe different for PUT/POST and GET requests as well - or different if you abort/reload/close while sending POST/PUT data from the browser to the server or reading the response from the server.
Network failure is a different issue, e.g. if you use mobile data in areas with less than perfect reception. It is not possible for principal reasons, to detect a network failure in a second, without false positives (considering active connections as broken).
The
signal(SIGPIPE, SIG_IGN)
does indeed tell a server running on a Linux operating system, to ignore if a client connection is closed by the client - otherwise, if one client connection is closed this way, the entire server stops (for all clients).
See
https://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properlyVarious alternatives are by no means portable between different operating systems.
Depending on what you want to cover or ignore, it might be able to modify `handle_cgi_request` accordingly.