Skip to content

WiFiClient.cpp::setTimeout not working properly? #2016

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

Closed
cyberman54 opened this issue Nov 4, 2018 · 8 comments
Closed

WiFiClient.cpp::setTimeout not working properly? #2016

cyberman54 opened this issue Nov 4, 2018 · 8 comments

Comments

@cyberman54
Copy link
Contributor

I'm trying to set a connection timeout before opening a wifi connection.
My code is:

const uint32_t RESPONSE_TIMEOUT = 30;
WiFiClientSecure client;
client.setTimeout(RESPONSE_TIMEOUT);
if (!client.connect(currentHost.c_str(), port)) {
    ESP_LOGI(TAG, "Cannot connect to %s", currentHost.c_str());
    display(3, " E", "connection lost");
    goto failure;
  }

This openes the wifi connection successful, but it logs this error:
[E][WiFiClient.cpp:236] setSocketOption(): 1006 : 9

0x1006 is defined as
#define SO_RCVTIMEO 0x1006 /* receive timeout */

but what means error 9 ?

@cyberman54
Copy link
Contributor Author

My fault: i set the client.setTimeout command at wrong place before opening the stream.
Closing this.

@cyberman54
Copy link
Contributor Author

I was wrong, code placement seems not to be the error cause.
So reopening this.

@Jeroen88
Copy link
Contributor

Jeroen88 commented Nov 5, 2018

As I understand it, the timeout is not used for the connection, but for reading and writing only. So you should use client.setTimeout() after client.connect().

I may have found the error code here, though: http://www.nongnu.org/lwip/2_0_x/group__infrastructure__errors.html

Beware, the timeout for WiFiClient (ie effectively what is called using WiFiClientSecure.setTimeout()) is not passed on to Stream, causing timeout errors while reading. See my comments at PR #1979.

@cyberman54
Copy link
Contributor Author

Thanks for linking your RP #1979 , it explains exactly the problems in which i ran.
So again i close this issue, hoping that PR #1979 will be merged soon.

@Jeroen88
Copy link
Contributor

Jeroen88 commented Nov 5, 2018

You're welcome :), you can use this PR by checking it out locally on your computer

@cyberman54
Copy link
Contributor Author

Did that already. But my goal is not to keep a local update.cpp at all...

@Jeroen88
Copy link
Contributor

Jeroen88 commented Nov 5, 2018

Sure, that is why I want it to be merged soon too!

@usmanshahid001
Copy link

int connect(IPAddress ip, uint16_t port, int32_t timeout);
i think connection timeout is 3rd parameter .

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

No branches or pull requests

3 participants