You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/01/04 03:10:58 UTC
[incubator-nuttx-apps] branch master updated (1b5b8c5 -> 538c757)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git.
from 1b5b8c5 lvgl: Add file system interface.
new 819454e apps/examples/webserver: When NSH app, allow terminating
new 538c757 apps/examples/webserver: nxstyle fixes
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
examples/webserver/webserver_main.c | 68 ++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 24 deletions(-)
[incubator-nuttx-apps] 01/02: apps/examples/webserver: When NSH app,
allow terminating
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 819454ee6ef2e885a04fca2ff7264d17d8215c17
Author: Nathan Hartman <59...@users.noreply.github.com>
AuthorDate: Sun Jan 3 17:58:04 2021 -0500
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 3a21b0b22263c06b5ba54ea2525521c8ca84b349
---
examples/webserver/webserver_main.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/examples/webserver/webserver_main.c b/examples/webserver/webserver_main.c
index e3f3e9f..9d2313f 100644
--- a/examples/webserver/webserver_main.c
+++ b/examples/webserver/webserver_main.c
@@ -197,6 +197,7 @@ int main(int argc, FAR char *argv[])
httpd_listen();
#endif
+#ifndef CONFIG_NSH_NETINIT
/* We are running standalone (as opposed to a NSH built-in app). Therefore
* we should not exit after httpd failure.
*/
@@ -208,5 +209,23 @@ int main(int argc, FAR char *argv[])
fflush(stdout);
}
+#else /* CONFIG_NSH_NETINIT */
+ /* We are running as a NSH built-in app. Therefore we should exit. This
+ * allows to 'kill -9' the webserver app, assuming it was started as a
+ * background process. For example:
+ *
+ * nsh> webserver &
+ * webserver [6:100]
+ * nsh> Starting webserver
+ *
+ * nsh> kill -9 6
+ * nsh> webserver_main: Exiting
+ */
+
+ printf("webserver_main: Exiting\n");
+ fflush(stdout);
+
+#endif /* CONFIG_NSH_NETINIT */
+
return 0;
}
[incubator-nuttx-apps] 02/02: apps/examples/webserver: nxstyle fixes
Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 538c757340eb7a07a8ae26d35570a84e4d59481a
Author: Nathan Hartman <59...@users.noreply.github.com>
AuthorDate: Sun Jan 3 18:00:55 2021 -0500
apps/examples/webserver: nxstyle fixes
apps/examples/webserver/webserver_main.c:
* Fix nxstyle errors.
---
examples/webserver/webserver_main.c | 49 +++++++++++++++++++------------------
1 file changed, 25 insertions(+), 24 deletions(-)
diff --git a/examples/webserver/webserver_main.c b/examples/webserver/webserver_main.c
index 9d2313f..0222190 100644
--- a/examples/webserver/webserver_main.c
+++ b/examples/webserver/webserver_main.c
@@ -110,7 +110,7 @@ int main(int argc, FAR char *argv[])
void *handle;
#endif
-/* Many embedded network interfaces must have a software assigned MAC */
+ /* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLES_WEBSERVER_NOMAC
mac[0] = 0x00;
@@ -156,34 +156,35 @@ int main(int argc, FAR char *argv[])
handle = dhcpc_open("eth0", &mac, IFHWADDRLEN);
- /* Get an IP address. Note: there is no logic here for renewing the address in this
- * example. The address should be renewed in ds.lease_time/2 seconds.
+ /* Get an IP address. Note: there is no logic here for renewing the
+ * address in this example. The address should be renewed in
+ * ds.lease_time/2 seconds.
*/
printf("Getting IP address\n");
if (handle)
{
- struct dhcpc_state ds;
- dhcpc_request(handle, &ds);
- netlib_set_ipv4addr("eth0", &ds.ipaddr);
-
- if (ds.netmask.s_addr != 0)
- {
- netlib_set_ipv4netmask("eth0", &ds.netmask);
- }
-
- if (ds.default_router.s_addr != 0)
- {
- netlib_set_dripv4addr("eth0", &ds.default_router);
- }
-
- if (ds.dnsaddr.s_addr != 0)
- {
- netlib_set_ipv4dnsaddr(&ds.dnsaddr);
- }
-
- dhcpc_close(handle);
- printf("IP: %s\n", inet_ntoa(ds.ipaddr));
+ struct dhcpc_state ds;
+ dhcpc_request(handle, &ds);
+ netlib_set_ipv4addr("eth0", &ds.ipaddr);
+
+ if (ds.netmask.s_addr != 0)
+ {
+ netlib_set_ipv4netmask("eth0", &ds.netmask);
+ }
+
+ if (ds.default_router.s_addr != 0)
+ {
+ netlib_set_dripv4addr("eth0", &ds.default_router);
+ }
+
+ if (ds.dnsaddr.s_addr != 0)
+ {
+ netlib_set_ipv4dnsaddr(&ds.dnsaddr);
+ }
+
+ dhcpc_close(handle);
+ printf("IP: %s\n", inet_ntoa(ds.ipaddr));
}
#endif
#endif /* CONFIG_NSH_NETINIT */