From 6615f46dd187f2989b608fe56a3624aed84b87e9 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 13 Jan 2010 15:56:56 +0000 Subject: [PATCH] Added header file, init function and changed function names --- apps/httpserver/httpserver-netconn.c | 29 ++++++++++++++++++++++------ apps/httpserver/httpserver-netconn.h | 6 ++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 apps/httpserver/httpserver-netconn.h diff --git a/apps/httpserver/httpserver-netconn.c b/apps/httpserver/httpserver-netconn.c index 2fcf034..8b77362 100644 --- a/apps/httpserver/httpserver-netconn.c +++ b/apps/httpserver/httpserver-netconn.c @@ -1,13 +1,19 @@ + #include "lwip/opt.h" #include "lwip/arch.h" #include "lwip/api.h" +#include "httpserver-netconn.h" + #if LWIP_NETCONN const static char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; -const static char http_index_html[] = "Congrats!

Welcome to our lwIP HTTP server!

This is a small test page."; +const static char http_index_html[] = "Congrats!

Welcome to our lwIP HTTP server!

This is a small test page, served by httpserver-netconn."; -void http_server_serve(struct netconn *conn) { +/** Serve one HTTP connection accepted in the http thread */ +static void +http_server_netconn_serve(struct netconn *conn) +{ struct netbuf *inbuf; char *buf; u16_t buflen; @@ -46,12 +52,16 @@ void http_server_serve(struct netconn *conn) { netbuf_delete(inbuf); } -int http_server() { +/** The main function, never returns! */ +static void +http_server_netconn_thread(void *arg) +{ struct netconn *conn, *newconn; + LWIP_UNUSED_ARG(arg); /* Create a new TCP connection handle */ conn = netconn_new(NETCONN_TCP); - LWIP_ERROR("http_server: invalid conn", (conn != NULL), return -1;); + LWIP_ERROR("http_server: invalid conn", (conn != NULL), return;); /* Bind to port 80 (HTTP) with default IP address */ netconn_bind(conn, NULL, 80); @@ -61,10 +71,17 @@ int http_server() { while(1) { newconn = netconn_accept(conn); - http_server_serve(newconn); + http_server_netconn_serve(newconn); netconn_delete(newconn); } - return 0; + return; +} + +/** Initialize the HTTP server (start its thread) */ +void +http_server_netconn_init() +{ + sys_thread_new("http_server_netconn", http_server_netconn_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); } #endif /* LWIP_NETCONN*/ diff --git a/apps/httpserver/httpserver-netconn.h b/apps/httpserver/httpserver-netconn.h new file mode 100644 index 0000000..7b84715 --- /dev/null +++ b/apps/httpserver/httpserver-netconn.h @@ -0,0 +1,6 @@ +#ifndef __HTTPSERVER_NETCONN_H__ +#define __HTTPSERVER_NETCONN_H__ + +void http_server_netconn_init(); + +#endif /* __HTTPSERVER_NETCONN_H__ */