/** * @brief TCP server main thread. * * @param [in] p is currently unused. */ THD_FUNCTION(tcp_server, p) { thread_t * helper = (thread_t *) p; chRegSetThreadName("TCP server"); struct netconn * conn; struct netconn * newconn; while (true) { /* Check DHCP status */ msg_t msg; /* Wait forever if not connected */ if(chMBFetch(&mb_server_config, &msg, TIME_INFINITE) == ERR_OK) { if(msg != dhcp_bound) { continue; } } /* Normal operation, DHCP freshly bound. */ conn = netconn_new(NETCONN_TCP); LWIP_ERROR("http_server: invalid conn", (conn != NULL), chThdExit(MSG_RESET);); err_t err; err = netconn_bind(conn, NULL, SERVER_THREAD_CONFIG_PORT); err = netconn_listen(conn); while (true) { err = netconn_accept(conn, &newconn); if (err != ERR_OK) continue; comm_init(newconn, helper); } } }