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|writable] methods #15376

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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.

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.

1 participant