-
Notifications
You must be signed in to change notification settings - Fork 1
Update client.connect() use #4
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
Conversation
Implicit boolean conversion will convert errors into 'true'.
Some gateways might disable port 80.
|
the documentation is wrong. all examples have the example can't fit all networks. the user will just have to adopt it to their network. many Ethernet libraries don't support secure layer |
Mine does; I follow that API spec. This is the big problem with this API spec and one of several reasons I don't love it. Inconsistency and weird choices abound. A Boolean-returning API is a little easier to work with, but then there needs to be a way to find the last error that occurred, and, unfortunately, there's no such standard for this. I've been thinking about how to do this, though. Currently, however, the only way to tell the difference between "timeout", "bad server", or "success" connection attempts is with those error codes. So for this case, it's actually more correct to check for "==1" because even if an API function returns a Related note from my README about the inconsistency in the Arduino examples related to
|
that is the thing with the established API. we can't fix it. we have to live with it |
It sounds like you're agreeing with my point that the API is what it is? This means we can't treat It's the same deal with #3 that was accepted. |
everybody does treat it as a boolean because of the official examples. I don't recommend going against it. |
The official examples are wrong. In any case, comparing using "==1" isn't wrong. Similar to PR #3 that was accepted. (See the |
Right, but the documentation "is what is" right now (see your post here: #4 (comment)). Here's the spec: https://www.arduino.cc/reference/en/libraries/ethernet/client.connect/ So are you proposing to use the documented spec or the examples that disagree with that spec? I've chosen to go with the documented spec for my API. |
hostByName is optional advanced function, it is not used so frequently and is not in the examples. most implementations return 1 or 0. only a few have other return values. I think I will initiate the change of the doc for |
I'll add: the examples were probably made without understanding how integers get transformed into Booleans in C++, so I'd personally use the spec.
That would be great, but if that changes, how does one tell the difference between a timeout, bad host lookup, some other error, or success? There needs to be either a reference/pointer argument where the error gets stored or some sort of "get last error" function. Otherwise, the API can't be used at all for robust applications. A simple Boolean return doesn't work. |
so it is Arduino and thing should be simple at top level. |
True. What about a timeout? Update: Let me answer myself: Check whether connected. |
so there is only port refused or timeout for not secured connection. port refused happens immediately, |
for secured connection esp8266 has getLastSSLError |
Summary of the two changes:
client.connect()
for an error; only '1' is success. Implicit Boolean conversion will turn non-zero errors intotrue
.