Skip to content

Refactor IO::Syscall as IO::Evented#7505

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
ysbaddaden:refactor/io-syscall-to-evented
Mar 15, 2019
Merged

Refactor IO::Syscall as IO::Evented#7505
straight-shoota merged 1 commit intocrystal-lang:masterfrom
ysbaddaden:refactor/io-syscall-to-evented

Conversation

@ysbaddaden
Copy link
Collaborator

@ysbaddaden ysbaddaden commented Mar 4, 2019

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 from IO::Buffered (e.g. evented_read instead of read_syscall_helper).

Refactors the FileDescriptor and Socket IO classes to move implementation details into IO::Evented to 1. reduce duplication, and 2. avoid direct accesses to internal details (such as @writers or @read_event).

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.
Copy link
Member

@straight-shoota straight-shoota left a 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?

@ysbaddaden
Copy link
Collaborator Author

Huum, I think it should be :nodoc:. Maybe moved to Crystal namespace, along Event and EventLoop. Maybe even moved to Crystal::System since it's only used on POSIX platforms.

@yxhuvud
Copy link
Contributor

yxhuvud commented Mar 4, 2019

(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.

Copy link
Member

@RX14 RX14 left a 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.

@ysbaddaden ysbaddaden requested a review from bcardiff March 7, 2019 09:42
@ysbaddaden
Copy link
Collaborator Author

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

@ysbaddaden
Copy link
Collaborator Author

@bcardiff it was already :)

Copy link
Member

@bcardiff bcardiff left a 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.

@bew
Copy link
Contributor

bew commented Mar 15, 2019

It looks like everybody agree, let's get going! 🚀
ok

@straight-shoota straight-shoota merged commit f9fde1a into crystal-lang:master Mar 15, 2019
@straight-shoota straight-shoota added this to the 0.28.0 milestone Mar 15, 2019
@straight-shoota
Copy link
Member

Thank you @ysbaddaden!

@ysbaddaden ysbaddaden deleted the refactor/io-syscall-to-evented branch March 15, 2019 23:23
urde-graven pushed a commit to urde-graven/crystal that referenced this pull request Mar 20, 2019
* '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)
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.

7 participants