-
Notifications
You must be signed in to change notification settings - Fork 635
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
Use generic typechecks, OTA add followRedirects #1974
Conversation
Based on gitter discussion, I tried adding this as a struct member with an earlier example static constexpr std::integral_constant<bool, value> value_type{}; Where Maybe something like is_detected is better for the reader? |
Yes, there are many nicer solutions ( |
Will do. gcc headers are a bit tricky to navigate to c/p everything needed, but I have tried implementation from clang and small example from sol2 issue tracker, which both build just fine: Current implementation was made up based on something in the gcc sources (i think i just grep'ed for true_type) and I wonder what is the reason for |
Adding
|
code/espurna/ota_httpupdate.ino
Outdated
t_httpUpdate_return _otaClientUpdate(const std::true_type&, T& instance, WiFiClient* client, const String& url) { | ||
if (client == nullptr) { | ||
client = std::make_unique<WiFiClient>().get(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw shouln't this be back where it was initially? check for has_WiFIClient_argument_t
there and supply it when true.
i don't remember the specifics (search is not helping...), but there were also a couple of issues with httpclient & wificlient destructor ordering. but, this may not be relevant if httpclient can handle wificlient missing and update() does not keep lingering connection / expects more actions.
edit: and even more so, isn't make_unique struct + object destroyed right after .get()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it inside the function because that means one place less to check the update() signature: https://github.com/xoseperez/espurna/pull/1974/files#diff-5727c97832f80d3ac6aedd50dbe75fd6L81-L90 - but yes, not sure if this is the best approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the second comment, WiFiClient is destroyed right after get().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that was not the case previously when it was called in the _otaClientFromHttp()
function? I tested OTA with these changes and I didn't run into any issues so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the case, unique_ptr lived while parent function was active.
idk how that works exactly... effectively, wificlient is no longer allocated and anything can claim that memory segment through new / malloc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. It could still check for arg availability though. Only cost is +2 lines, everything is known at compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So split _otaClientFromHttp()
method and call the appropriate one from _otaClientFrom()
with the type check? Or you mean a different way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant right in the fromhttp, optionally creating wificlient. unique_ptr structure could be initialized with nullptr, .get()
will return that null pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but I'm not sure I follow - feel free to commit what you have in mind :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://godbolt.org/z/yu9fxq <-
Maybe I misunderstood the question. make_unique<T>() == unique_ptr<T>(new T())
, so we just hide make_unique under the check
This PR changes the following:
CREATE_CHECK(class, function, params...)
macro to generate typechecksOTA_CLIENT_HTTPUPDATE
module instead ofOTA_CLIENT_HTTPUPDATE_2_3_0_COMPATIBLE
macroOTA_CLIENT_HTTPUPDATE
module forfollowRedirects()
, enable if available