httpd: prepare for https: move initialization code to shared function

This commit is contained in:
goldsimon 2017-03-22 22:41:24 +01:00
parent 2f3b00efb4
commit afaa7d9561

View File

@ -2550,6 +2550,23 @@ http_accept(void *arg, struct altcp_pcb *pcb, err_t err)
return ERR_OK; return ERR_OK;
} }
static void
httpd_init_pcb(struct altcp_pcb *pcb, u16_t port)
{
err_t err;
if (pcb) {
altcp_setprio(pcb, HTTPD_TCP_PRIO);
/* set SOF_REUSEADDR here to explicitly bind httpd to multiple interfaces */
err = altcp_bind(pcb, IP_ANY_TYPE, port);
LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
pcb = altcp_listen(pcb);
LWIP_ASSERT("httpd_init: tcp_listen failed", pcb != NULL);
altcp_accept(pcb, http_accept);
}
}
/** /**
* @ingroup httpd * @ingroup httpd
* Initialize the httpd: set up a listening PCB and bind it to the defined port * Initialize the httpd: set up a listening PCB and bind it to the defined port
@ -2558,7 +2575,6 @@ void
httpd_init(void) httpd_init(void)
{ {
struct altcp_pcb *pcb; struct altcp_pcb *pcb;
err_t err;
#if HTTPD_USE_MEM_POOL #if HTTPD_USE_MEM_POOL
LWIP_MEMPOOL_INIT(HTTPD_STATE); LWIP_MEMPOOL_INIT(HTTPD_STATE);
@ -2570,14 +2586,7 @@ httpd_init(void)
pcb = altcp_tcp_new_ip_type(IPADDR_TYPE_ANY); pcb = altcp_tcp_new_ip_type(IPADDR_TYPE_ANY);
LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL); LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL);
altcp_setprio(pcb, HTTPD_TCP_PRIO); httpd_init_pcb(pcb, HTTPD_SERVER_PORT);
/* set SOF_REUSEADDR here to explicitly bind httpd to multiple interfaces */
err = altcp_bind(pcb, IP_ANY_TYPE, HTTPD_SERVER_PORT);
LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
pcb = altcp_listen(pcb);
LWIP_ASSERT("httpd_init: tcp_listen failed", pcb != NULL);
altcp_accept(pcb, http_accept);
} }
#if LWIP_HTTPD_SSI #if LWIP_HTTPD_SSI