I have a webserver that has a serverside handler per HTTP-GET and path. The return-value of the handler-function is the HTTP-response.
E.g.
String handleGetList (Params ps)
{
String str = "<ul>";
// ...
str += "</ul>";
retrun str;
}
Now think of a handler that should execute an axtion that terminates the server (e.g. shutdown, stop HTTP-server, ...).
How can I do so to have the action and also the response??
String handleTerminate (Params ps)
{
system ("shutdown");
retrun "OK";
}
Shutdown before return would not send the response.
Response before shutdown would not executes the shutdown.
How to get both?
Sure I can set a marker for some external app that does the shutdown after the response is sent but maybe there is an easier way.
I did it now this way.
Because of & the system does not wait till it ends and with the sleep the whole handler can finish before the shutdown happens.