From c94ec825c79ad995be953b65e69d359c6b3a22bc Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 14 Oct 2022 00:41:07 +1300 Subject: [PATCH 1/3] Run tests on Windows. --- .github/workflows/test.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c718fac9..a9680530 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,6 +35,9 @@ jobs: - os: ubuntu ruby: head experimental: true + - os: windows + ruby: head + experimental: true steps: - uses: actions/checkout@v3 From 7e89986079f45c42a829f641bb968da07b71e6b3 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 6 Dec 2022 23:39:41 +1300 Subject: [PATCH 2/3] Disable `io_read`/`io_write` hooks on Windows. --- lib/async/scheduler.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/async/scheduler.rb b/lib/async/scheduler.rb index 21915994..3f25bcbe 100644 --- a/lib/async/scheduler.rb +++ b/lib/async/scheduler.rb @@ -23,6 +23,10 @@ def self.supported? true end + def self.windows? + ::RUBY_PLATFORM =~ /mswin|mingw|cygwin/ + end + def initialize(parent = nil, selector: nil) super(parent) @@ -166,7 +170,7 @@ def io_wait(io, events, timeout = nil) timer&.cancel end - if ::IO::Event::Support.buffer? + if ::IO::Event::Support.buffer? and !Scheduler.windows? def io_read(io, buffer, length, offset = 0) @selector.io_read(Fiber.current, io, buffer, length, offset) end From e29580c3718aa07948d5489049750f78b36b91b2 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Tue, 6 Dec 2022 23:54:20 +1300 Subject: [PATCH 3/3] Use threads for non-blocking IO on Windows. --- lib/async/scheduler.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/async/scheduler.rb b/lib/async/scheduler.rb index 3f25bcbe..22d83bbc 100644 --- a/lib/async/scheduler.rb +++ b/lib/async/scheduler.rb @@ -170,13 +170,27 @@ def io_wait(io, events, timeout = nil) timer&.cancel end - if ::IO::Event::Support.buffer? and !Scheduler.windows? - def io_read(io, buffer, length, offset = 0) - @selector.io_read(Fiber.current, io, buffer, length, offset) - end - - def io_write(io, buffer, length, offset = 0) - @selector.io_write(Fiber.current, io, buffer, length, offset) + if ::IO::Event::Support.buffer? + if Scheduler.windows? + def io_read(io, buffer, length, offset = 0) + Thread.new do + buffer.read(io, length, offset) + end.value + end + + def io_write(io, buffer, length, offset = 0) + Thread.new do + buffer.write(io, length, offset) + end.value + end + else + def io_read(io, buffer, length, offset = 0) + @selector.io_read(Fiber.current, io, buffer, length, offset) + end + + def io_write(io, buffer, length, offset = 0) + @selector.io_write(Fiber.current, io, buffer, length, offset) + end end end