ARMmbed / mbed-client-for-azure

Azure IoT Device SDK port for Mbed OS
Apache License 2.0
5 stars 4 forks source link

Fix socket send block error #7

Closed ccli8 closed 3 years ago

ccli8 commented 3 years ago

Environment

mbed-os-example-for-azure 7b4116b0392e41b7ae0cdd7faaa7ee0d36e630a7

Target NUMAKER_IOT_M487

Toolchain Arm Compiler 6.13

Connectivity ESP8266 WiFi

Description

In my case, TLS handshake fails. Looking into, I find that socket is configured to non-blocking and send block case NSAPI_ERROR_WOULD_BLOCK is not well handled.

https://github.com/ARMmbed/mbed-client-for-azure/blob/16f9b31e41c1bb89b776418b6dc109b92b0d911c/mbed/adapters/socketio_mbed_os5.cpp#L383-L389

This PR changes to retry instead of error out on send block case NSAPI_ERROR_WOULD_BLOCK.

            else if (send_result < 0)
            {
                
                if (send_result == NSAPI_ERROR_WOULD_BLOCK) {
                    thread_sleep_for(10);
                
                } else {
                    indicate_error(socket_io_instance);
                    return -1;
                }
            }