MediaTek-Labs / Arduino-Add-On-for-LinkIt-SDK

Arduino board support package for LinkIt 7697
https://docs.labs.mediatek.com/resource/linkit7697-arduino/en
34 stars 33 forks source link

TLSClient.available() is very slow #52

Closed pccr10001 closed 6 years ago

pccr10001 commented 7 years ago

Hello,

I am using TLSClient + PubSubClient for AWS IoT MQTT Client. And I found TLSClient.available() stop for 4 secs on mbedtls_ssl_read() function.

pablosun commented 6 years ago

Hi @pccr10001, this seems to be server-response related. When connecting to howsmyssl.com the TLSClient::available() took 1~6ms to return, which seems to be pretty fast.

If this issue persists in your case, you can try set the socket timeout option:

  1. open the file TLSClient.cpp in %LOCALAPPDATA%\Arduino15\packages\LinkIt\hardware\linkit_rtos\0.9.5\libraries\LWiFi\src

  2. find the method TLSClient::connectImpl

  3. After the call to mbedtls_ssl_set_bio, insert following code snippet:

        int timeout_ms = 300; // set Timeout to 300ms
        struct timeval {
            long      tv_sec;
            long      tv_usec;
        };
        struct timeval interval = {timeout_ms / 1000, (timeout_ms % 1000) * 1000};
        if (interval.tv_sec < 0 || (interval.tv_sec == 0 && interval.tv_usec <= 0))
        {
            interval.tv_sec = 0;
            interval.tv_usec = 100;
        }
        setsockopt(m_cntx.net_ctx.fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&interval, sizeof(struct timeval));
pablosun commented 6 years ago

close until we can reproduce this issue.