Skip to content

Crystal::EventLoop::FileDescriptor#open now sets the non/blocking flag#15754

Merged
straight-shoota merged 3 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/event-loop-must-handle-blocking-arg-2
May 19, 2025
Merged

Crystal::EventLoop::FileDescriptor#open now sets the non/blocking flag#15754
straight-shoota merged 3 commits intocrystal-lang:masterfrom
ysbaddaden:refactor/event-loop-must-handle-blocking-arg-2

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented May 6, 2025

Moves the responsibility to set FILE_FLAG_OVERLAPPED or O_NONBLOCK to each event loop, so they can eventually own the blocking flag.

There is no change in behavior, yet: the event loops still set the flag depending on the blocking argument.

Refactors the IO::FileDescriptor and File internal constructors so we can instantiate the object without changing the blocking state (already set).

Extracted from #15685.
Depends on #15750 and #15753.

@ysbaddaden ysbaddaden force-pushed the refactor/event-loop-must-handle-blocking-arg-2 branch from a20deaf to a7d89af Compare May 12, 2025 09:29
@@ -7,7 +7,7 @@ abstract class Crystal::EventLoop
# `nil`.
#
# Returns the system file descriptor or handle, or a system error.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Returns the system file descriptor or handle, or a system error.
# Returns the system file descriptor or handle and the actual
# blocking state, or a system error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must return the blocking value because:

  • it may not be the same value (event-loop can decide otherwise);
  • win32 needs to save the actual value as @system_blocking in the File object;

end

# :nodoc:
def self.from_fd(path : String, fd : Int, *, blocking = false, encoding = nil, invalid = nil)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That constructor was already unused.

@ysbaddaden ysbaddaden marked this pull request as ready for review May 12, 2025 09:40
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