apps/examples/webserver/webserver_main.c: Init network & run forever only if not builtin app. Infer from CONFIG_NSH_BUILTIN_APPS if we are a NSH built-in app or not. If built-in app (CONFIG_NSH_BUILTIN_APPS defined) then we assume network is initialized prior to webserver starting and we exit on webserver failure. If running standalone (CONFIG_NSH_BUILTIN_APPS is undefined) then behavior is unchanged: webserver initializes network and runs forever.

This commit is contained in:
Nathan Hartman 2019-07-26 11:04:05 -06:00 committed by Gregory Nutt
parent 4fd1058200
commit 3a21b0b222

View File

@ -101,6 +101,11 @@ int main(int argc, FAR char *argv[])
int webserver_main(int argc, char *argv[]) int webserver_main(int argc, char *argv[])
#endif #endif
{ {
#ifndef CONFIG_NSH_BUILTIN_APPS
/* We are running standalone (as opposed to a NSH built-in app). Therefore
* we need to initialize the network before we start.
*/
struct in_addr addr; struct in_addr addr;
#if defined(CONFIG_EXAMPLES_WEBSERVER_DHCPC) || defined(CONFIG_EXAMPLES_WEBSERVER_NOMAC) #if defined(CONFIG_EXAMPLES_WEBSERVER_DHCPC) || defined(CONFIG_EXAMPLES_WEBSERVER_NOMAC)
uint8_t mac[IFHWADDRLEN]; uint8_t mac[IFHWADDRLEN];
@ -185,6 +190,7 @@ int webserver_main(int argc, char *argv[])
printf("IP: %s\n", inet_ntoa(ds.ipaddr)); printf("IP: %s\n", inet_ntoa(ds.ipaddr));
} }
#endif #endif
#endif /* CONFIG_NSH_BUILTIN_APPS */
#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_TCP
printf("Starting webserver\n"); printf("Starting webserver\n");
@ -195,12 +201,18 @@ int webserver_main(int argc, char *argv[])
httpd_listen(); httpd_listen();
#endif #endif
#ifndef CONFIG_NSH_BUILTIN_APPS
/* We are running standalone (as opposed to a NSH built-in app). Therefore
* we should not exit after httpd failure.
*/
while (1) while (1)
{ {
sleep(3); sleep(3);
printf("webserver_main: Still running\n"); printf("webserver_main: Still running\n");
fflush(stdout); fflush(stdout);
} }
#endif /* CONFIG_NSH_BUILTIN_APPS */
return 0; return 0;
} }