Initially I was buffering the page, setting the content-length, and then sending it with a single espconn_sent which seemed fine when it was much smaller. With more than one client hitting it, there was an occasional memory allocation error which I initially attributed to fragmentation, but was probably because espconn_sent was doubling the requirements.
I would prefer to buffer up to a packet size and stream the response using http chunked transfer-encoding. This minimizes my memory usage and increases response time by streaming the content as it is generated. Also gets around having to specify the unknown content-length in the response header.
The problem is that espconn_sent is asynchronous and allocates it's own output buffer, so if I buffer 10k of content, espconn_sent allocates another 10k and copies all of the data to be sent but does nothing until control goes back to the cpu. If I send multiple smaller packets, espconn_sent buffers each packet until the return to the main loop.
Potential solutions in order of preference?
1. Something I missed and can't seem to find that does one of the following or better.
2. A synchronous version of espconn_sent so that data does not have to be copied or buffered.
3. An equivalent to the yield() call as provided by esp8266/Arduino to allow the main loop to catch up and flush the buffers.
4. Continue as written hoping I don't exhaust memory.
Dealing with this buffered output makes the complexity go up considerably when you move beyond the trivial case, looking for an elegant solution.
I think right now I am handling the response directly from the recvcb .. if that makes any difference vs running off a post callback.
Thanks..Statistics: Posted by afnid — Fri Jul 31, 2015 12:23 pm
]]>