nuttx-apps/examples/webserver
Nathan Hartman 819454ee6e apps/examples/webserver: When NSH app, allow terminating
The examples/webserver app can be built in two modes:

    (1) in standalone mode, or
    (2) as a NSH built-in app.

When run in standalone mode, the webserver program is responsible for
bringing up the network (including DHCP if configured).  Also, the
webserver program must never exit, so if httpd fails (i.e., if
httpd_listen() returns), webserver_main() goes into an endless loop.

When run as a NSH built-in app, network bring-up is the responsibility
of other processes and the webserver program assumes the network is
already properly configured when it starts.  Also, if httpd_listen()
returns, the webserver program should terminate.

Prior to this change, the webserver program would *not* terminate,
even when running as a NSH built-in app.  For example:

    nsh> webserver &
    webserver [6:100]
    nsh> Starting webserver

    nsh> kill -9 6
    nsh> webserver_main: Still running
    nsh> webserver_main: Still running
    nsh> webserver_main: Still running
    nsh> webserver_main: Still running

The line "webserver_main: Still running" would be forever printed
every 3 seconds, however httpd_listen() is no longer running and the
webserver is not functional.

This change makes the webserver play nicely when running as a NSH
built-in app.  With this change applied:

    nsh> webserver &
    webserver [6:100]
    nsh> Starting webserver

    nsh> kill -9 6
    nsh> webserver_main: Exiting

apps/examples/webserver/webserver_main.c:

    * main(): Infer from CONFIG_NSH_BUILTIN_APPS if this is a
      standalone program or a NSH built-in app.  (See [1], where
      similar logic was added to decide whether to do network bring-up
      or not.)  If standalone, run forever as before.  If built-in
      app, exit when httpd terminates.

References:
[1] Commit 3a21b0b222
2021-01-03 21:10:38 -06:00
..
httpd-fs build: Remve the unnecessary .gitignore 2020-05-23 15:56:35 +01:00
.gitignore build: Remve the unnecessary .gitignore 2020-05-23 15:56:35 +01:00
cgi.c From patch attached to nuttx/ Bitbucket Issue #136 from Vlado Vidovic: 2018-11-23 17:29:07 -06:00
cgi.h Rename apps/examples/uip to apps/examples/webserver 2014-07-03 17:31:17 -06:00
Kconfig apps/examples/webserver/Kconfig: The webserver "app" allows for DHCP client to be enabled. However, the Kconfig infrastructure does not contain EXAMPLES_WEBSERVER_DHCPC config. 2018-11-08 18:48:28 -06:00
Make.defs apps/: In all Make.def files, append to CONFIGURED_APPS patch with the absolute path. 2019-10-17 11:33:59 -06:00
Makefile build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
webserver_main.c apps/examples/webserver: When NSH app, allow terminating 2021-01-03 21:10:38 -06:00