-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Refactor IO::Syscall as IO::Evented #7505
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
Evented
is closer to what the module is trying to achieve (abstract event loop details), and method naming follows that fromIO::Buffered
(e.g.evented_read
instead ofread_syscall_helper
).Refactors the
FileDescriptor
andSocket
IO classes to move implementation details intoIO::Evented
to 1. reduce duplication, and 2. avoid direct accesses to internal details (such as@writers
or@read_event
).