arduino-libraries / ArduinoIoTCloud

Home Page:https://app.arduino.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BearSSLClient::write fails to send data buffer > 512 bytes

pennam opened this issue · comments

The problem is here:

  • If more than 512 bytes are written, then result == 512. In the next 'while' round, size is still it's original value, which is incorrect. This is working:
size_t BearSSLClient::write(const uint8_t *buf, size_t size)
{
  size_t written = 0;
  size_t toWrite = size;

  while (written < toWrite) {
    int result = br_sslio_write(&_ioc, buf, size);

    if (result < 0) {
      break;
    }

    buf += result;
    written += result;
    size -= result;
  }

  if (written == toWrite && br_sslio_flush(&_ioc) < 0) {
    return 0;
  }

  return written;
}