Skip to content

Add EventLoop#wait_readable, #wait_writable methods methods#15376

Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-event-loop-wait-readable-and-writable
Feb 6, 2025
Merged

Add EventLoop#wait_readable, #wait_writable methods methods#15376
straight-shoota merged 4 commits intocrystal-lang:masterfrom
ysbaddaden:feature/add-event-loop-wait-readable-and-writable

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Jan 27, 2025

Adds two methods to the Crystal::EventLoop interfaces to wait on a file descriptor or socket readiness (read or write) without doing the actual read or write operations, which can be delegated to an external library.

This provides a semi-public interface to work around #15374:

file_descriptor = IO::FileDescriptor.new(LibC.some_fd, blocking: false)

event_loop = Crystal::EventLoop.current
event_loop.wait_readable(file_descriptor)
LibC.do_something(fd)

This is implemented for the polling event loops (epoll, kqueue) as well as libevent since these were straightforward.

Windows is left unimplemented. It might be implemented with WSAPoll running in a thread or ProcessSocketNotifications to associate sockets to a completion port. See Winsock socket state notifications for more details.

Related to RFC #0007 and RFC #0009.

@straight-shoota straight-shoota added this to the 1.16.0 milestone Feb 5, 2025
@straight-shoota straight-shoota merged commit 8823b75 into crystal-lang:master Feb 6, 2025
70 checks passed
@ysbaddaden ysbaddaden deleted the feature/add-event-loop-wait-readable-and-writable branch February 6, 2025 11:13
@straight-shoota straight-shoota changed the title Add EventLoop#wait_[readable|writable] methods Add EventLoop#wait_readable, #wait_writable methods methods Feb 6, 2025
@straight-shoota straight-shoota linked an issue Jul 22, 2025 that may be closed by this pull request
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.

Return wait_readable or something equivalent

2 participants