Thanks to visit codestin.com
Credit goes to github.com

Skip to content

extmod/uos: Expose stream ioctl constants, an ioctl() function. #10031

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

damz
Copy link
Contributor

@damz damz commented Nov 20, 2022

This PR exposes a new uos.ioctl() function, and the related ioctl constants.

I have three reasons to do this:

  • It would allow us to write unit tests for ussl: Fix polling of SSL sockets #9871;
  • It would remove the need for each custom implementation of io.IOBase to re-define all these constants;
  • It enables advanced use cases where an user-space implementation of ioctl(MP_STREAM_POLL) needs to forward that request to an underlying stream (like ussl has to do)

@codecov-commenter
Copy link

Codecov Report

Merging #10031 (1bd5038) into master (ac5934c) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master   #10031   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files         156      156           
  Lines       20520    20520           
=======================================
  Hits        20179    20179           
  Misses        341      341           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Nov 28, 2022
@dpgeorge
Copy link
Member

I can see how this is a useful addition. But my reservations with it are:

  • it's not CPython compatible (CPython has no os.ioctl, although subtly what's added here is uos.ioctl)
  • it doesn't match how other functionality like close, flush exist as methods on the stream object (not functions in uos)
  • adding constants is expensive in terms of code size and all ports would need to include them for them to be useful (otherwise if you can't rely on them being there on all ports you must use integers for portable code)

You can also see that mp_stream_ioctl_obj() already exists and provides this ioctl functionality (it's just not wired up to many classes).

The main use case here (as far as I see it, at least in the immediate case at hand) is for unit testing. So to move forward I'd suggest just adding mp_stream_ioctl_obj() to the locals dict tables of file/stream objects that need it for testing #9871, and guard it by #if MICROPY_UNIX_COVERAGE.

@damz
Copy link
Contributor Author

damz commented Dec 15, 2022

Sounds very reasonable, closing this.

@damz damz closed this Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants