0

A bit unsure where to look for this one...

Context:

  • HTML5 web page, that uses HTML5 EventSource / server-side events to get refresh notifications
  • OpenWrt BarrierBreaker server, running uHTTPd as the web server
  • a two-level CGI script that provides the server-side events:
    1. the CGI is a shell script (ash, not bash), that parses QUERY_STRING, and calls...
    2. a C application that do the true data extraction (from an SQLite database) and pushes the data to the web page

Everything works, except for a little detail: when the web page is closed, the C application keeps running. Since it doesn't expect any user input, its current structure is a simple while(1). So after some time, the openwrt box has dozens of copies of the app running.

So the question: how can the application be changed to detect that the client isn't there anymore, and that it should quits?

Thanks

[Edit]

Since posting this a few hours ago, i investigated if the information was somehow available in the script's input stream. It appears it isn't.

I also found http://html5doctor.com/server-sent-events/ that describes a strategy to do exactly this in a Node.js environment, but I have no idea how to translate this in a script-based one.

[/Edit]

jmr
  • 196
  • 1
  • 1
  • 10
  • In the unlikely case someone else stumbles on this question, I found the following reads interesting about the CGI standard: http://stackoverflow.com/questions/2089271/i-never-really-understood-what-is-cgi http://tools.ietf.org/html/draft-robinson-www-interface-00 – jmr Apr 19 '15 at 05:25
  • For now, given that the SSE specification states that the client will reconnect if the server closes the connexion, I used a "middle-ground" approach and decided that the C application will terminates after a specific amount of time. I'm still looking for suggestions, though. – jmr Apr 19 '15 at 05:27

0 Answers0