Skip to content
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

Add EventLoop#wait_readable, #wait_writable methods methods #15376

Conversation

ysbaddaden
Copy link
Contributor

@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
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