crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.21k stars 1.61k forks source link

Add `EventLoop::FileDescriptor` module #14639

Closed straight-shoota closed 1 month ago

straight-shoota commented 1 month ago

Extracts the system interface for FileDescriptor operations on the event loop to a EventLoop module.

This implements part of https://github.com/crystal-lang/rfcs/pull/7

Related: #14643 does the same for Socket

beta-ziliani commented 1 month ago

The methods in the wasi interface are new, should they be tested?

straight-shoota commented 1 month ago

@beta-ziliani Not sure what you mean which methods would need to be tested on Wasi? This isn't really adding any new behaviour, it's just shifting implementations from one class to another.

beta-ziliani commented 1 month ago

I guess I'm missing the part in which WASI uses unix/file_descriptor.cr. But in this case, doesn't it make sense to abstract these two instead of copying it?

straight-shoota commented 1 month ago

WASI event loop and libevent are completely different things. I suppose we could drop the evented wrapper from the WASI implementation, because it does not support non-blocking operations anyway. I left it in for now because evented_read etc. also do error handling. This will be another refactor after this and #14643 are merged.