Fix #888, AsyncEventSourceMessage::send()

Tested with 16 kB message size: Respect number of already sent bytes
in successive calls to AsyncEventSourceMessage::send()
This commit is contained in:
Ulrich Lukas
2020-11-16 07:10:08 +01:00
parent f6fff3f91e
commit 8012f6e9eb

View File

@@ -137,16 +137,17 @@ size_t AsyncEventSourceMessage::ack(size_t len, uint32_t time) {
return 0; return 0;
} }
// This could also return void as the return value is not used.
// Leaving as-is for compatibility...
size_t AsyncEventSourceMessage::send(AsyncClient *client) { size_t AsyncEventSourceMessage::send(AsyncClient *client) {
const size_t len = _len - _sent; if (_sent >= _len) {
if(client->space() < len){ return 0;
return 0; }
} const size_t len_to_send = _len - _sent;
size_t sent = client->add((const char *)_data, len); auto position = reinterpret_cast<const char*>(_data + _sent * sizeof(*_data));
if(client->canSend()) const size_t sent_now = client->write(position, len_to_send);
client->send(); _sent += sent_now;
_sent += sent; return sent_now;
return sent;
} }
// Client // Client