Skip to content

esp32/errno: fix lwip errno's for esp32 #5968

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

Closed
wants to merge 1 commit into from

Conversation

tve
Copy link
Contributor

@tve tve commented Apr 24, 2020

This commit addresses #5752 and fixes the issue cleanly in expectation of #5825 where it otherwise shows up through the mbedssl stack. I couldn't remember a case I could test at this stage, I'm not sure there is any because the errno's are currently fixed-up explicitly in modsocket.c. It's only with the fixes to mbedtls for non-blocking sockets that the errors are checked before that fix-up and then the mess surfaces.
(I've made the changes in this PR a while ago on my fork but had them as part of #5819 and pulled them out today to keep the individual PRs/commits cleanly focused.)

@dpgeorge
Copy link
Member

It's only with the fixes to mbedtls for non-blocking sockets that the errors are checked before that fix-up and then the mess surfaces.

Do you mean that mbedtls is directly calling in to the C-level lwip API, and not going through esp32/modsocket (which would otherwise fix the errno values)?

I'd be reluctant to patch lwip like done in this PR. Would much prefer to fix the errnos in modsocket.c.

@tve
Copy link
Contributor Author

tve commented Apr 28, 2020

It's only with the fixes to mbedtls for non-blocking sockets that the errors are checked before that fix-up and then the mess surfaces.

Do you mean that mbedtls is directly calling in to the C-level lwip API, and not going through esp32/modsocket (which would otherwise fix the errno values)?

No. mbedtls calls the stream read/write. As you know, these don't raise errors, they return MP_STREAM_ERROR and set the errno. The current modsocket just does *errcode = errno so that needs to change to go through the same mapping as when send/recv raise an exception.

I'd be reluctant to patch lwip like done in this PR. Would much prefer to fix the errnos in modsocket.c.

Hmm, I actually thought that patching LwIP like this is far more elegant than to let it produce some wrong error codes and then try to correct them. Thoughts:

  • Patching LwIP the way I did is clean in that there is a cleanly defined list of errors and the patch provides exactly what we want, and there is no confusion in the code whether EXXX or MP_EXXX should be used.
  • Remapping error numbers means tracking down in esp-idf which of the several definitions of error numbers is pertinent, then creating a mapping switch statement for 7 of the 14 error codes that LwIP produces (if I counted correctly, probably best to remap all 14 even if half are identity mappings).

You tell me which you want...

@dpgeorge
Copy link
Member

What about updating to IDF v4.1 so this is not needed? See #6413; I'm happy to do the work to update that.

@tve
Copy link
Contributor Author

tve commented Sep 18, 2020

That works for me.

@tve
Copy link
Contributor Author

tve commented Dec 24, 2020

fixed by #6613

@tve tve closed this Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants