Refactor IO::Syscall as IO::Evented#7505
Conversation
Evented is closer to what the module is trying to achieve (abstract event loop details) than Syscall. Reuses the method namings from IO::Buffered (e.g. `evented_read` instead of `read_syscall_helper`). Avoids some duplication found in IO::FileDescriptor (system/unix) and Socket. Isolates implementation details back into IO::Evented, instead of having direct accesses to internal implementation details (such as `@writers`) of IO::Evented.
straight-shoota
left a comment
There was a problem hiding this comment.
While you're at it, could you add a short documentation to IO::Evented, and maybe some of its methods?
|
Huum, I think it should be |
|
(quite OT, but related to the greater topic of evented IO on Linux) I wonder how much of this will change when https://lwn.net/Articles/776703/ is fully merged and accessible from userspace. |
RX14
left a comment
There was a problem hiding this comment.
I think I originally designed it expecting to be able to adapt the class for windows, so I put the events outside the mixin. I don't think I will be able to reuse this so eventually I think IO::Evented will move under Crystal::System and become UNIX-only.
That's just to say expect future refactors: I won't know for sure until I try and get windows networking code working. This is fine to merge as-is.
|
Having them moved back into IO::Evented helped in my MT experiments, thought I moved most libevent responsibility into EventLoop, and use a single Event on Fiber directly, which holds the status (e.g. added, canceled). See ysbaddaden@2ea421a |
|
@bcardiff it was already :) |
bcardiff
left a comment
There was a problem hiding this comment.
I agree with @straight-shoota that would be great to have some documentation, even if it's moved to crystal namespace. But that can come later. It's a great refactor.
|
Thank you @ysbaddaden! |
* 'master' of github.com:crystal-lang/crystal: Change the font-weight used in Playground (crystal-lang#7552) Fix formatting absolute paths (crystal-lang#7560) Refactor IO::Syscall as IO::Evented (crystal-lang#7505) YAML: fix test checking serialization of slices for libyaml 0.2.2 (crystal-lang#7555) Let Array#sort only use `<=>`, and let `<=>` return `nil` for partial comparability (crystal-lang#6611) Update `to_s` and `inspect` to have similar signatures accross the stdlib (crystal-lang#7528) Fix restriction of valid type vs free vars (crystal-lang#7536) Rewrite macro spec without executing a shell command (crystal-lang#6962) Suggest `next` when trying to break from captured block (crystal-lang#7406) Fix GenericClassType vs GenericClassInstanceType restrictions (crystal-lang#7537) Add human readable formatting for numbers (crystal-lang#6314) Add command and args to execvp error message (crystal-lang#7511) Implement Set#add? method (crystal-lang#7495)

I started this refactor in my MT experiments, but I think it stands on its own:
Eventedis closer to what the module is trying to achieve (abstract event loop details), and method naming follows that fromIO::Buffered(e.g.evented_readinstead ofread_syscall_helper).Refactors the
FileDescriptorandSocketIO classes to move implementation details intoIO::Eventedto 1. reduce duplication, and 2. avoid direct accesses to internal details (such as@writersor@read_event).