Remove cruft

This commit is contained in:
Sergey Lyubka 2022-03-31 18:07:15 +01:00
parent 6c909f8935
commit 4e0039625e

View File

@ -8,8 +8,6 @@ static const char *s_root_dir = ".";
static const char *s_listening_address = "http://0.0.0.0:8000"; static const char *s_listening_address = "http://0.0.0.0:8000";
static time_t s_boot_timestamp = 0; static time_t s_boot_timestamp = 0;
static struct mg_connection *s_sntp_conn = NULL; static struct mg_connection *s_sntp_conn = NULL;
static struct net_mgmt_event_callback mgmt4_cb;
static bool s_network_initialised = false;
// Event handler for the listening connection. // Event handler for the listening connection.
// Simply serve static files from `s_root_dir` // Simply serve static files from `s_root_dir`
@ -63,33 +61,12 @@ static void logfn(const void *ptr, size_t len, void *userdata) {
printk("%.*s", (int) len, (char *) ptr); printk("%.*s", (int) len, (char *) ptr);
} }
static void netcb(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
char hr_addr[NET_IPV4_ADDR_LEN];
if (mgmt_event == NET_EVENT_IPV4_ADDR_ADD) {
for (int i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) {
struct net_if_addr *if_addr = &iface->config.ip.ipv4->unicast[i];
if (if_addr->addr_type != NET_ADDR_DHCP || !if_addr->is_used) continue;
MG_INFO(
("IPv4 address: %s", net_addr_ntop(AF_INET, &if_addr->address.in_addr,
hr_addr, NET_IPV4_ADDR_LEN)));
s_network_initialised = true;
break;
}
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct mg_mgr mgr; struct mg_mgr mgr;
mg_log_set(s_debug_level); mg_log_set(s_debug_level);
mg_log_set_callback(logfn, NULL); mg_log_set_callback(logfn, NULL);
// Wait until network is initialised
net_mgmt_init_event_callback(&mgmt4_cb, netcb, NET_EVENT_IPV4_ADDR_ADD);
net_mgmt_add_event_callback(&mgmt4_cb);
while (!s_network_initialised) k_sleep(K_MSEC(100));
mg_mgr_init(&mgr); mg_mgr_init(&mgr);
mg_http_listen(&mgr, s_listening_address, cb, &mgr); mg_http_listen(&mgr, s_listening_address, cb, &mgr);