Fri 07 Feb 2014 12:16:05 PM UTC, original submission:
lwip-devel on 13-05-23:
"I am also hunting a bug in the httpserver_raw, when including SSI tags; it finds the tag, sends the preceding data, then the tag. But then the sending length is never reset so it sends the remaining page at the tag length.
As a result serving a webpage takes 2-3 seconds if its a 4K file with an SSI tag in the <title>.
The problem seems to be around :1351 where I think len is being mistaken for something else, where its actually the length of the previously sent section (last tag length). Could someone more familiar with the code take a look too?
After working through it this patch appears to solve the problem. It might not be a good way of doing things but it works. I'm not getting any out of memory errors if writing more then the buf (which was stalling SYN ACK for 2-3 seconds) and the speed of replying to a GET has improved, reducing the chance of a retry.
--- C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/httpserver_raw/httpd.c Mon Dec 17 19:07:22 2012
+++ C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/httpserver_raw/httpd - Copy.c Thu May 23 12:56:32 2013
@@ -1197,7 +1197,7 @@
* the buffer contents looking for SSI tags. */
while((ssi->parse_left) && (err == ERR_OK)) {
/* @todo: somewhere in this loop, 'len' should grow again... */
- if (len == 0) {
+ if (tcp_sndbuf(pcb) == 0) {
return data_to_send;
}
switch(ssi->tag_state) {
@@ -1344,15 +1344,18 @@
if (ssi->tag_end > hs->file) {
/* How much of the data can we send? */
#if LWIP_HTTPD_SSI_INCLUDE_TAG
- if(len > ssi->tag_end - hs->file) {
+ if(tcp_sndbuf(pcb) > ssi->tag_end - hs->file) {
len = (u16_t)(ssi->tag_end - hs->file);
}
#else /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
- if(len > ssi->tag_started - hs->file) {
+ if(tcp_sndbuf(pcb) > ssi->tag_started - hs->file) {
/* we would include the tag in sending */
len = (u16_t)(ssi->tag_started - hs->file);
}
#endif /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
+ else {
+ len = tcp_sndbuf(pcb);
+ }
err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
if (err == ERR_OK) {
@@ -1390,16 +1393,20 @@
if(ssi->tag_end > hs->file) {
/* How much of the data can we send? */
#if LWIP_HTTPD_SSI_INCLUDE_TAG
- if(len > ssi->tag_end - hs->file) {
+ if(tcp_sndbuf(pcb) > ssi->tag_end - hs->file) {
len = (u16_t)(ssi->tag_end - hs->file);
}
#else /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
LWIP_ASSERT("hs->started >= hs->file", ssi->tag_started >= hs->file);
- if (len > ssi->tag_started - hs->file) {
+ if (tcp_sndbuf(pcb) > ssi->tag_started - hs->file) {
/* we would include the tag in sending */
len = (u16_t)(ssi->tag_started - hs->file);
}
#endif /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
+ else {
+ len = tcp_sndbuf(pcb);
+ }
+
if (len != 0) {
err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
} else {
@@ -1432,8 +1439,10 @@
if(ssi->tag_index < ssi->tag_insert_len) {
/* We are sending the insert string itself. How much of the
* insert can we send? */
- if(len > (ssi->tag_insert_len - ssi->tag_index)) {
+ if(tcp_sndbuf(pcb) > (ssi->tag_insert_len - ssi->tag_index)) {
len = (ssi->tag_insert_len - ssi->tag_index);
+ } else {
+ len = tcp_sndbuf(pcb);
}
/* Note that we set the copy flag here since we only have a
@@ -1444,7 +1453,8 @@
HTTP_IS_TAG_VOLATILE(hs));
if (err == ERR_OK) {
data_to_send = 1;
- ssi->tag_index += len;
+ if (tcp_sndbuf(pcb) != 0)
+ ssi->tag_index += len;
/* Don't return here: keep on sending data */
}
} else {
"
|