Implement move operations for HTTPClient by paulocsanz · Pull Request #8236 · esp8266/Arduino (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation3 Commits5 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

paulocsanz

Fixes #8231

This implements move constructor and assignment for HTTPClient, intended to support std::optional proper usage. It's not clear to me if this is the right place to test for compilation errors.

@paulocsanz

@mcspr

Late sorry for not being clear, since I did not literally mean to implement the move yourself with every member, and it should be apparent it is not really... nice looking and there is a better way to handle this.

Just for consideration: master...mcspr:ptr-wrap-test
(and strictly solving the problem at hand, idk if I'd call it something nice either. real change I'd like would touch much more stuff, this is just to keep most of existing code touching the client and headers)
With the idea to have a protocol for certain members handled through the member class itself, and not to manually micro-manage everything.

mcspr

@paulocsanz

@paulocsanz

Your changes seem way better! Since you already implemented it, wouldn't you prefer to provide a PR and I close this one?

Just a suggestion, a name like ObserverPtr/NonOwningPtr seem more intuitive than ClientWrapper.

It seems a std::unique_ptr with a no-op deleter would work as well, but seem hackish.

My first instinct was using std::optional<std::reference_wrapper<WiFiClient>>, but it may be overkill to bring all those dependencies for this small feature.

@mcspr mcspr mentioned this pull request

Jul 24, 2021

mcspr added a commit that referenced this pull request

Oct 13, 2021

@mcspr

Allow HTTPClient to be placed inside of movable classes (e.g. std::optional, requested in the linked issue) or to be returned from functions. Class logic stays as-is, only the underlying member types are changed.

Notice that WiFiClient connection object is now copied, and the internal ClientContext will be preserved even after the original WiFiClient object was destroyed.

replaces #8236 resolves #8231 and, possibly #5734

hasenradball pushed a commit to hasenradball/Arduino that referenced this pull request

Nov 18, 2024

@mcspr @hasenradball

Allow HTTPClient to be placed inside of movable classes (e.g. std::optional, requested in the linked issue) or to be returned from functions. Class logic stays as-is, only the underlying member types are changed.

Notice that WiFiClient connection object is now copied, and the internal ClientContext will be preserved even after the original WiFiClient object was destroyed.

replaces esp8266#8236 resolves esp8266#8231 and, possibly esp8266#5734

2 participants

@paulocsanz @mcspr