WIZnet-MbedEthernet / WIZnetInterface

arm Mbed-OS 5 WIZnet chipset driver (W7xxx, W5/6xxx)
8 stars 2 forks source link

wait_readable returns 0 instead of NSAPI_ERROR_WOULD_BLOCK #10

Open strange-v opened 4 years ago

strange-v commented 4 years ago

According to the Mbed documentation socket.recv method should return NSAPI_ERROR_WOULD_BLOCK in case it non-blocking or timeout.

But if we check the code we can see that it returns size in case of timeout (zero in many cases).

        if ((size1 > req_size) || (wait_time_ms != (-1) && t.read_ms() > wait_time_ms)) 
        {
            return size1;
        }
    }
    return NSAPI_ERROR_WOULD_BLOCK;

It seems incorrect. Am I wrong?

strange-v commented 4 years ago

After further investigation, I've found one more issue in this piece of code. Even if "wait_readable" returns NSAPI_ERROR_WOULD_BLOCK, "WIZnetInterface::socket_recv" returns zero, because recved_size is always zero in this case.

Either recved_size should be declared like this int recved_size = -1; or condition should be if(recved_size > 0){