ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By Hari K
#23734 The SDK documentation clearly states that espconn_sent() cannot be called again until the espconn_sent_cb() callback is received.

I'm guessing that this also means that the data buffer passed to espconn_sent() cannot also be used until after the callback is received. This makes sense from the SDK implementor's point of view, since they wouldn't have to make another copy of the data.

However, I notice that esphttpd is placing buffers on the stack and then passing those to espconn_sent() in at least two places. If my supposition is true (and once again this is only a guess), this might be an issue.

Has this possibility been considered before? Has anyone from EspressIf explicitly confirmed that the data pointer can be reused on return?
User avatar
By tve
#23783 Mhh, interesting point. I perused some older Esp SDK sources and it indeed looks to me like the data should not be changed until the callback occurs. Specifically, what called is https://github.com/nodemcu/nodemcu-firmware/blob/0ad574705d1a22b9ebc62bc198e6db9e792244e0/app/lwip/app/espconn_tcp.c#L152-L199 and it saves away the pointer to any data not yet sent. Now what happens is that with the std MSS there probably is enough buffer space for the amounts that esphttpd tries to send, so probably nothing bad happens. I do know that trying to use the liblwip version with an MSS of 536 bytes fails miserably. This may be a reason for that...
User avatar
By kolban
#23921 Could we not malloc() a buffer and pass that buffer in ... and then when we receive a notification that the send has completed, free the storage?

There is also a mysterious property in the espconn_set_opt() function called ESPCONN_COPY that talks about copying the transmitted data ... it talks about a buffer of 2920 bytes ... but doesn't say if this is one buffer or one per send().