Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a buffer to send data to client #52

Closed
Laxilef opened this issue Dec 7, 2023 · 5 comments · Fixed by #56
Closed

Using a buffer to send data to client #52

Laxilef opened this issue Dec 7, 2023 · 5 comments · Fixed by #56
Assignees
Labels
enhancement New feature or request

Comments

@Laxilef
Copy link
Contributor

Laxilef commented Dec 7, 2023

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?

@Laxilef
Copy link
Contributor Author

Laxilef commented Dec 9, 2023

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?

@LennartHennigs
Copy link
Owner

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

Cheers
l.

@Laxilef
Copy link
Contributor Author

Laxilef commented Dec 9, 2023

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

@LennartHennigs
Copy link
Owner

Cool!

@Laxilef
Copy link
Contributor Author

Laxilef commented Dec 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants