PoC: let the event loop decide blocking or non blocking#15685
Closed
ysbaddaden wants to merge 17 commits intocrystal-lang:masterfrom
Closed
PoC: let the event loop decide blocking or non blocking#15685ysbaddaden wants to merge 17 commits intocrystal-lang:masterfrom
ysbaddaden wants to merge 17 commits intocrystal-lang:masterfrom
Conversation
Actually moves the internal `Crystal::System::File.open` method to be the responsibility of the event loops, so we can choose to open asynchronously or non-blocking when the event loop supports it (i.e. io_uring).
This will be used to determine whether we want to set `O_NONBLOCK` or `FILE_FLAG_OVERLAPPED` depending on the active event loop backend. We use it for `IO.pipe` and `IO::FileDescriptor`.
Replaces `Crystal::System::Socket#create_handle` and gives full control to the event loop backend to set `O_NONBLOCK` or `WSA_FLAG_OVERLAPPED` as it see fits —which the IOCP event loop already did.
…e the non/blocking flag
This was referenced May 6, 2025
This was referenced May 20, 2025
Collaborator
Author
|
Almost everything from the PoC has been extracted & merged. The only the notable exception is the default blocking behavior for files, and its |
Collaborator
Author
|
Closing this proof of concept PR. It has been fully extracted into individual pull requests 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The experimental branch as per my thread in #15652. Not meant to be merged. Multiple smaller PRs shall be extracted.
Overall:
File.openis moved toCrystal::EventLoop(for Add io_uring event loop #15634).Extracted as Add
Crystal::EventLoop::FileDescriptor#open#15750.Crystal::EventLoop#opendecides to setO_NONBLOCK,FILE_FLAG_OVERLAPPEDorWSA_FLAG_OVERLAPPEDon the IO objects (for io_uring again).Extracted as
Crystal::EventLoop::FileDescriptor#opennow sets the non/blocking flag #15754.File: theblockingargument now only has an effect on opening the file:falseon Linux it won't block the current thread anymore (io_uring will never block), whennilthe file type is checked (for details see The event loops should handle the non-blocking behavior of files, fildes and sockets #15652);FILE_FLAG_OVERLAPPEDso file IO are always async on Windows, which required a couple patches (Fix async append to file in IOCP #15681 and Fix: reopen asyncFilepassed toProcess.execand.run(win32) #15703).Extracted as Let the event loop decide the blocking mode of
File#15930 and Detach execution context scheduler from running thread during blocking syscall #15871.Socketnow defaults toblocking: nil:blocking: true, otherwise the event loops setO_NONBLOCK(but io_uring won't set it);WSA_FLAG_OVERLAPPED(no change);blockingarg.Extracted as Refactor
Socketblocking mode #15804.The behavior of
IO::FileDescriptorshouldn't have changed;IO.pipenow respects the Crystal::EventLoop behavior (expects blocking or nonblocking) unless a blocking value is specified.Extracted as Refactor
IO.pipeblocking mode #15823.UNIXSocket.pairnow respects the Crystal::EventLoop behavior (expects blocking or nonblocking).Extracted into
Crystal::EventLoop::FileDescriptor#opennow sets the non/blocking flag #15754.The BREAKING CHANGE is that of undocumented behavior:
File: theblockingarg doesn't set#blocking=anymore;Socket: theblockingarg now defaults tonil.Related to #15634