[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-devel] SMTP base64 patch, HTTPD question.
From: |
Ben Whitten |
Subject: |
Re: [lwip-devel] SMTP base64 patch, HTTPD question. |
Date: |
Thu, 23 May 2013 13:02:01 +0100 |
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 {