Skip to content

Uniform behaviour of WiFiClientSecure and WiFiClient setTimeout() #6562

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

Merged
merged 4 commits into from
Apr 26, 2022

Conversation

gonzabrusco
Copy link
Contributor

Summary

WiFiClientSecure setTimeout does nothing (literally nothing), while WiFiClient setTimeout really modifies the socket send and receive timeouts. This is not an uniform behaviour and I think this should be fixed. This is my proposal but I would like you to review it very thoroughly in case I'm ommiting something.

Now both classes have a class variable called _timeout. These variables are setted to the original timeout defaults in the constructors of each class (3000 ms for WiFiClient and 30000ms for WiFiClientSecure).

setTimeout() now sets this variable but also tries to configure the socket in case the connection was previously established (this is the original WiFiClient behaviour except for the class variable setting). This variable (_timeout) will be used for each new connection WiFiClient and WiFiClientSecure make.

In case of WiFiClientSecure there's also setHandshakeTimeout(), this is kept as is, but any interaction between _timeout and sslclient->handshake_timeout was removed because now they should remain independent timeouts.

Previous to this PR, you could not set the send and receive timeouts of WiFiClientSecure. They were always forced to 30000 ms. Now the behaviour is similar to WiFiClient.
Also previously with WiFiClient, if you set the timeout BEFORE the connection, it would end up ignored because the socket was not created and the configuration was not saved (there was no _timeout class variable).

Honestly I must admit that I felt a bit surprised to see these inconsistencies on such an important part of the arduino core. Please review it and let me know what you think. This is just a proposal but feel free to change everything you want.

Impact

Now you can call setTimeout() before a connection in WiFiClient.
Now you can call setTimeout() with a WiFiClientSecure and actually set something...
WiFiClientSecure send and receive timeouts now are independent of the handshake timeout.

Related links

I created this bug report a few days ago (#6429 (comment))

@github-actions
Copy link
Contributor

github-actions bot commented Apr 11, 2022

Unit Test Results

0 files  0 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0

Results for commit 634cca3.

♻️ This comment has been updated with latest results.

@dexion
Copy link

dexion commented Apr 13, 2022

Why did you not set Stream's timeout in WifiClientSecure like Client::setTimeout(seconds * 1000); ?
_timeout variable is overloaded in ancestor and it wouldn't be set for Stream's functions like Stream::readStringUntil which uses Stream::timedRead? BTW _timeout should not be int, it can't be less zero. I would prefer use unsigned int for clarity )

@gonzabrusco
Copy link
Contributor Author

Why did you not set Stream's timeout in WifiClientSecure like Client::setTimeout(seconds * 1000); ? _timeout variable is overloaded in ancestor and it wouldn't be set for Stream's functions like Stream::readStringUntil which uses Stream::timedRead? BTW _timeout should not be int, it can't be less zero. I would prefer use unsigned int for clarity )

About the type, I used int following what WiFiClientSecure used originally, to be consistent. Also, all the prototypes of the class use "int32_t timeout" as the passing type for the timeout. So I respected that too. Nevertheless, I agree with you that maybe all should be an unsigned type.

About the Client::setTimeout(seconds * 1000);, actually I didn't do It because I wasn't sure if WiFiClient should do it in the first place. What they are modifying calling the Client::Timeout is the timeout in the Stream Class as you said. But I think that with WiFiClient and WiFiClientSecure that timeout is meaningless because everything is handled at the LWIP level. But I could be wrong, I wasn't really sure about that so I decided to "not change it".

@me-no-dev
Copy link
Member

Hi @gonzabrusco ! Your implementation looks great. Thanks!

@me-no-dev me-no-dev merged commit 823fe77 into espressif:master Apr 26, 2022
Jason2866 added a commit to tasmota/arduino-esp32 that referenced this pull request Apr 26, 2022
* LittleFs is working with C3

* Delete .skip.esp32c3

* Add support for extra flash images (espressif#6625)

This PR adds support for uploading additional flash images (e.g. Adafruit Tiny UF2 bootloader) specified in board manifests.

Additionally, the PR switches the PlatformIO CI script to the upstream version of the ESP32 dev-platform (basically reverts changes introduced in espressif#5387 as they are no longer required).

* publish.yml: Remove a leftover parenthesis that was making the workflow (espressif#6620)

Description of Change

Remove a leftover parenthesis that was making the workflow that was making the workflow invalid.

Tests scenarios

Github Workflow.

Related links

https://github.com/espressif/arduino-esp32/actions/runs/2213167501

Signed-off-by: Abdelatif Guettouche <[email protected]>

* Enable LittleFs sketches for C3 (espressif#6618)

* LittleFs is working with C3

* Delete .skip.esp32c3

* Update LittleFS PlatformIO example (espressif#6617)

* Added RainMaker support on Arduino IDE for ESP32-C3/S2/S3 (espressif#6598)

* Added RainMaker support on Arduino IDE for ESP32-C3/S2/S3

Closes espressif#6573
Note related to the issue espressif#6435

* Touch change to init only selected GPIO. (espressif#6609)

* Separated init for touch / channel called by touchRead()

* compile error

* Fixed touch_V2 + ISR

* Allow BluetoothSerial::connect() with specified channel and more options (espressif#6380)

* BTAddress const, add bool()

* BTAdvertisedDevice: const functions

* BluetoothSerial: add: getChannels, add isClosed, add read/peek timeout, add connect with channel#

* BluetoothSerial: add sec_mask, role in ::connect

* BluetoothSerial add discover and connect with channel number example

* DiscoverConnect: add SPP_ENABLED check

* DiscoverConnect: disable on esp32s3

* Fixes stream load memory leak in WifiSecureClient for SSL CACert, Certificate, and (espressif#6387)

Private Key. Issue presented during any subsequent invocation of loadCACert, loadCertificate, and
loadPrivateKey, respectively, after the first invocation.

* Call i2c_set_timeout in i2cSetClock (espressif#6537)

* Uniform behaviour of WiFiClientSecure and WiFiClient setTimeout() (espressif#6562)

* Uniform timeout WiFiClient-WiFiClientSecure

* Added missing prototype

* Add socket check on setTimeout

* enh(log) salvage TAG from ESP_IDF log-statements > (espressif#6567)

by converting result log-rows from the 1st line to the 2nd (`NET` is the tag):
```
[ 73419][D][telelogger.cpp:915] telemetry(): state: 33C

[ 73419][D][telelogger.cpp:915] telemetry(): [NET] state: 33C
```

Co-authored-by: Me No Dev <[email protected]>

* add AirM2M_CORE_ESP32C3 board (espressif#6613)

* add AirM2M_CORE_ESP32C3 board

* Added Unexpected Maker Reflow Master Pro (UM RMP) board (espressif#6630)

Fixed wrong SCK and MISO pins for TinyS2

* Tasmota changes (#24)

* Update install-arduino-core-esp32.sh

* Update CMakeLists.txt

* Update Esp.cpp

* Update Updater.cpp

Co-authored-by: Valerii Koval <[email protected]>
Co-authored-by: Abdelatif Guettouche <[email protected]>
Co-authored-by: Pedro Minatel <[email protected]>
Co-authored-by: Jan Procházka <[email protected]>
Co-authored-by: Christian Ferbar <[email protected]>
Co-authored-by: Billy <[email protected]>
Co-authored-by: Paul <[email protected]>
Co-authored-by: Gonzalo Brusco <[email protected]>
Co-authored-by: Kostis Anagnostopoulos <[email protected]>
Co-authored-by: Me No Dev <[email protected]>
Co-authored-by: Darren Cheng <[email protected]>
Co-authored-by: Unexpected Maker <[email protected]>
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

Successfully merging this pull request may close these issues.

WiFiClientSecure::setTimeout() inconsistency with WiFiClient::setTimeout()
3 participants