LennartHennigs/ESPTelnet

Using a buffer to send data to client

Closed this issue · 5 comments

Hi,
Great library, thanks!

I noticed that data is sent to telnet one character at a time. This takes longer than if we sent 32 characters at a time, for example.
This sometimes triggers the watchdog.
Is it possible to use a buffer?

I found out that we have to define a size_t write(const uint8_t* data, size_t size) method to send data more than one character at a time:

  size_t write(const uint8_t* data, size_t size) override {
    if (client && isConnected()) {
      return client.write(data, size);
    } else {
      return 0;
    }
  }

Because the standard implementation in Print simply loops through all the characters and prints them one at a time:

/* default implementation: may be overridden */
size_t Print::write(const uint8_t *buffer, size_t size)
{
    size_t n = 0;
    while(size--) {
        n += write(*buffer++);
    }
    return n;
}

Should I create a PR?

Hey,
Thanks for reaching out. Sure!
Out of curiosity - did you test how much faster it got when using a buffer?

Cheers
l.

Yes, on Esp32 it’s faster x5, on esp8266 х2

In fact, the speed gain depends on the length of the line to be printed. Most likely now there is 1 char/packet, and when using a buffer, N char/packet are sent.