- Sun Feb 22, 2015 9:57 pm
#10476
Couple of issues here:
If you conn:send more than 1460 bytes without waiting for the "sent" callback, you will eventually overflow the internal buffers. I think the buffer will actually hold 2 packets, but 2920 bytes is still not a lot, especially if you want to serve images. I use coroutines to yield execution until the callback is called.
If you start handling post, you can get multiple receive callbacks, one per packet. Either way, closing the connection in onReceive will not take you very far.
You can save some heap by combining parseRequest and parseUri into a single regular expression. string.match can can match \r\n.
See my post in Script Examples "My take on the lhttpd port" for some more ideas... we're basically trying to do the same thing. Mine handles post, images, server templates (through pre-compilation to .lua files), and large files. Memory is tight, but it seems to be working for a decently useful application (a web-based ide). Take a look at the code in the dropbox link, but be warned it is in heavy development.