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

0 15 asyncwebserver 2.1.0 features #3799

Conversation

willmmiles
Copy link
Collaborator

@willmmiles willmmiles commented Mar 7, 2024

This PR leverages the new features in the proposed AsyncWebServerWLED 2.1.0 build. In particular:

  • AsyncWebServerWLED 2.1.0 exposes its PROGMEM ContentType constants; use them where appropriate
  • AsyncWebServerWLED 2.1.0 accepts Strings for server.on() requests, so we don't have to cast PROGMEM to const char * and rely on the alignment fault handler to correctly construct;
  • AsyncWebServerWLED 2.1.0 introduces a SharedBuffer type that can be explicitly constructed and moved without the extra heap allocation and indirection of AsyncWebSocketMessageBuffer. This eliminates the deprecation warnings for that type.

@willmmiles
Copy link
Collaborator Author

@blazoncek You were asking about the warning fixes - these are the relevant patches.

@blazoncek
Copy link
Collaborator

Thanks.

So basically it is

AsyncWebSocketSharedBuffer newBuff(size);
...
ws->text(std::move(newBuff));

If I understand this (new to me) C++ syntax it says "use move constructor" when calling text() method? Is this correct?

@willmmiles
Copy link
Collaborator Author

Correct. The move operation is intended to make it clear that the buffer is being "given" to the web server code to manage. Moves like this are meant to communicate the ownership semantics to a code reader, without requiring a reader to know a priori that some random function is expecting to take responsibility for future deallocation. (And all this with no - or at least minimal - runtime cost.)

...though as I write this, I realize there's probably still an API design weakness there; the accepting function should probably insist on an unshared buffer (and internally promote it to shared if necessary) to be clear that it's not OK to write to the buffer after passing it. Next iteration!

These were mostly PROGMEM already, but every little bit helps.
Rather than relying on the exception handler, indicate the
__FlashStringHelper type so the correct String constructor is
used.
Eliminate the extra indirection and allocate shared buffers directly.
@willmmiles willmmiles force-pushed the 0_15-asyncwebserver-2.1.0-features branch from 08797a9 to 3b13629 Compare March 16, 2024 15:53
@willmmiles
Copy link
Collaborator Author

Superseded by #3828

@willmmiles willmmiles closed this Mar 16, 2024
@willmmiles willmmiles deleted the 0_15-asyncwebserver-2.1.0-features branch March 16, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants