-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
mbedtls and detecting non-blocking reads during handshaking #424
Comments
Thanks @nkolban, this looks good (and correct) to me. Are you able to please rewrite the commit message so it summarises the fix? something like:
Would be ideal. If you're not comfortable rewriting git history in this way then that's OK, I can rewrite the message when I push it into our internal merge queue. |
Sorry sir, I'm not good at Git ... :-( |
igrr
added a commit
that referenced
this issue
Mar 15, 2017
turmary
pushed a commit
to Seeed-Studio/Seeed_Arduino_mbedtls
that referenced
this issue
Jan 22, 2020
…ockets Previous code read non-blocking status via fcntl first, which resets errno. Closes #424 espressif/esp-idf#424 Merges #425 espressif/esp-idf#425
turmary
pushed a commit
to Seeed-Studio/Seeed_Arduino_mbedtls
that referenced
this issue
Jan 22, 2020
mbedtls port: Fix detection of EWOULDBLOCK/EAGAIN with non-blocking sockets Previous code read non-blocking status via fcntl first, which resets errno. * Closes #424 espressif/esp-idf#424 * Merges #425 espressif/esp-idf#425 See merge request !575
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we attempt to use a non-blocking socket with mbedtls we receive a failure. I dug deeply into this and believe I have found the resolution.
If we look at this function:
https://github.com/espressif/esp-idf/blob/master/components/mbedtls/port/net.c#L204
The intent is to determine if an error reported by a previous socket call was caused because the socket is non blocking. The return code is 0 if the last error was NOT caused by being a non-blocking socket while the return code is 1 if the last error was because we WERE a non-blocking socket. The logic is:
This sound sensible enough, however there is perhaps a flaw in the implementation. The we check "if the last error was because we were non-blocking" is to ASK the socket about its last error. We don't use
errno
because we are multi-threaded and premptable. Again, on the surface, that took makes sense. However in test number 1, we perform anfcntl
against the socket to determine if it is blocking or non-blocking ... and that resets the error condition that was present on the socket when the function was called. What this means is that the original error is lost.The text was updated successfully, but these errors were encountered: