diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-31 23:05:51 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-31 23:05:51 +0000 |
commit | b351b752486c1693392faed106a8a77609006656 (patch) | |
tree | 8b04048671d38afda5fd5fbcea2ae16a9da8bcbc /apps/netutils/webserver/httpd.c | |
parent | f8d292453df82fde56d2e4674ba78b5885fed899 (diff) | |
download | px4-nuttx-b351b752486c1693392faed106a8a77609006656.tar.gz px4-nuttx-b351b752486c1693392faed106a8a77609006656.tar.bz2 px4-nuttx-b351b752486c1693392faed106a8a77609006656.zip |
The content for uIP web server demo is no longer canned, but is not built dynameically (Thanks to Max Holtzberg)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5073 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils/webserver/httpd.c')
-rw-r--r-- | apps/netutils/webserver/httpd.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/apps/netutils/webserver/httpd.c b/apps/netutils/webserver/httpd.c index 434cfec5a..c7c4a2291 100644 --- a/apps/netutils/webserver/httpd.c +++ b/apps/netutils/webserver/httpd.c @@ -97,7 +97,7 @@ static const char g_httpextensiongif[] = ".gif"; static const char g_httpextensionjpg[] = ".jpg"; static const char g_http404path[] = "/404.html"; -static const char g_httpindexpath[] = "/index.html"; +static const char g_httpindexpath[] = "/index.shtml"; static const char g_httpcmdget[] = "GET "; @@ -273,11 +273,27 @@ static int httpd_addchunk(struct httpd_state *pstate, const char *buffer, int le return OK; } +static int httpd_flush(struct httpd_state *pstate) +{ + int ret = 0; + + if (pstate->ht_sndlen > 0) + { + httpd_dumpbuffer("Outgoing buffer", pstate->ht_buffer, pstate->ht_sndlen); + ret = send(pstate->ht_sockfd, pstate->ht_buffer, pstate->ht_sndlen, 0); + if (ret >= 0) + { + pstate->ht_sndlen = 0; + } + } + return ret; +} + static int send_headers(struct httpd_state *pstate, const char *statushdr, int len) { char *ptr; int ret; - + nvdbg("HEADER\n"); ret = httpd_addchunk(pstate, statushdr, len); if (ret < 0) { @@ -340,16 +356,23 @@ static int httpd_sendfile(struct httpd_state *pstate) { if (send_headers(pstate, g_httpheader200, strlen(g_httpheader200)) == OK) { - ptr = strchr(pstate->ht_filename, ISO_period); - if (ptr != NULL && - strncmp(ptr, g_httpextensionshtml, strlen(g_httpextensionshtml)) == 0) - { - ret = handle_script(pstate); - } - else - { - ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len); - } + if (httpd_flush(pstate) < 0) + { + ret = ERROR; + } + else + { + ptr = strchr(pstate->ht_filename, ISO_period); + if (ptr != NULL && + strncmp(ptr, g_httpextensionshtml, strlen(g_httpextensionshtml)) == 0) + { + ret = handle_script(pstate); + } + else + { + ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len); + } + } } } @@ -357,11 +380,10 @@ static int httpd_sendfile(struct httpd_state *pstate) if (ret == OK && pstate->ht_sndlen > 0) { - httpd_dumpbuffer("Outgoing buffer", pstate->ht_buffer, pstate->ht_sndlen); - if (send(pstate->ht_sockfd, pstate->ht_buffer, pstate->ht_sndlen, 0) < 0) - { - ret = ERROR; - } + if (httpd_flush(pstate) < 0) + { + ret = ERROR; + } } return ret; @@ -500,4 +522,5 @@ int httpd_listen(void) void httpd_init(void) { + httpd_fs_init(); } |