mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-24 08:45:10 +03:00
Previously, _write_some function would be called each time TCP stack notifies the application that some data was delivered (via the `sent` callback). In turn, _write_some would obtain more data to be sent from the DataSource. In case of a DataSource backed by a Stream, this would read from a stream. Some libraries (such as SD) may call `yield` and other blocking operations from Stream read function, which can not be used in TCP stack callbacks. This change moves the data sending loop back into the Arduino task, with a negligible loss of performance. TCP callback now wakes the main task via `esp_schedule`, which performs stream read and provides more data to the TCP stack. Possible future optimization would be to buffer Stream data ahead of time. That way, buffered data could be sent immediately from the TCP callback. On the other hand, this optimization would need extra TCP_MSS of temporary storage, per connection. Fixes #2399.