Change MSP TcpSocket to dynamically allocate its buffers #3240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the TCP/IP socket used for doing MSP config over wifi to delay allocating its buffers and packet converters the first time a connection is established. Reduces RAM usage by 3632 bytes.
The code is barely changed, just moved all into the TCPSOCKET class. Companion to #3238 for getting back to stable amounts of RAM for the webui. I do solemnly swear this is the last 3.x PR I'll submit.
Testing
Use Betaflight 4.4.3 and Configurator 10.9.0.
It seems the Betaflight Configurator 10.10.0 application has removed the ability to connect to a tcp:// port, or at least I can't figure out what the new secret way is to do so. I had to use 10.9.0 to test. They do still appear to support sockets for SITL (and therefore it should still work), but I'm not sure how to get the 10.10.0 Configurator to accept an IP address, and also the mDNS doesn't autodetect the receiver, which the 10.9.0 Configurator does. An older Android 10.10.0-dev client works too (c97deaf).
I also found Betaflight 4.5.2 to really be troublesome to use a socket connection, so I tested with 4.4.3. The connection happens and data starts coming, but the Setup page never loads on 4.5.x. Even on 4.4.x sometimes it just immediately closes the connection, but reconnecting again it works fine. This happens even on older ExpressLRS versions.
Bugs
The old code was also leaking memory by not freeing the AsyncClient when it disconnected, but they're really small so it wasn't a huge deal. I fixed it anyway.