Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 3, 2024
1 parent b6efb43 commit 0fe638b
Show file tree
Hide file tree
Showing 39 changed files with 166 additions and 160 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:

- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
8 changes: 4 additions & 4 deletions benchmark/instantiate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'benchmark/ips'
require 'fiber'
require "benchmark/ips"
require "fiber"

require_relative '../lib/event'
require_relative "../lib/event"

GC.disable

Expand Down
10 changes: 5 additions & 5 deletions benchmark/readable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'benchmark/ips'
require 'fiber'
require 'console'
require "benchmark/ips"
require "fiber"
require "console"

require_relative '../lib/event'
require_relative "../lib/event"

Event::Selector.constants.each do |name|
selector = Event::Selector.const_get(name).new(Fiber.current)
Expand Down
8 changes: 4 additions & 4 deletions benchmark/server/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'async'
require 'async/io/tcp_socket'
require "async"
require "async/io/tcp_socket"

port = Integer(ARGV.pop || 9090)

Async do |task|
server = Async::IO::TCPServer.new('localhost', port)
server = Async::IO::TCPServer.new("localhost", port)

loop do
peer, address = server.accept
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server/bake.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

SERVERS = [
"compiled",
Expand All @@ -19,7 +19,7 @@ def default
end

def build
compiler = ENV.fetch('CC', 'clang')
compiler = ENV.fetch("CC", "clang")
system(compiler, "compiled.c", "-o", "compiled", chdir: __dir__)
end

Expand All @@ -28,7 +28,7 @@ def build
# @parameter duration [Integer] The duration of the test.
def benchmark(connections: 8, threads: 1, duration: 1)
port = 9095
wrk = ENV.fetch('WRK', 'wrk')
wrk = ENV.fetch("WRK", "wrk")

SERVERS.each do |server|
$stdout.puts [nil, "Benchmark #{server}..."]
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'scheduler'
require_relative "scheduler"

scheduler = DirectScheduler.new
Fiber.set_scheduler(scheduler)
Expand All @@ -19,7 +19,7 @@
RESPONSE_SIZE = RESPONSE.set_string(RESPONSE_STRING)

Fiber.schedule do
server = TCPServer.new('localhost', port)
server = TCPServer.new("localhost", port)

loop do
peer, address = server.accept
Expand Down
8 changes: 4 additions & 4 deletions benchmark/server/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'scheduler'
require 'io/nonblock'
require_relative "scheduler"
require "io/nonblock"

#scheduler = DirectScheduler.new
scheduler = Scheduler.new
Expand All @@ -16,7 +16,7 @@
RESPONSE = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n"

Fiber.schedule do
server = TCPServer.new('localhost', port)
server = TCPServer.new("localhost", port)
server.listen(Socket::SOMAXCONN)

loop do
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'socket'
require "socket"

port = Integer(ARGV.pop || 9090)
server = TCPServer.new('localhost', port)
server = TCPServer.new("localhost", port)

loop do
peer = server.accept
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server/loop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'socket'
require "socket"

port = Integer(ARGV.pop || 9090)

server = TCPServer.new('localhost', port)
server = TCPServer.new("localhost", port)

loop do
peer, address = server.accept
Expand Down
8 changes: 4 additions & 4 deletions benchmark/server/scheduler.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

$LOAD_PATH << File.expand_path("../../lib", __dir__)
$LOAD_PATH << File.expand_path("../../ext", __dir__)

require 'io/event'
require "io/event"

require 'socket'
require 'fiber'
require "socket"
require "fiber"

class Scheduler
def initialize(selector = nil)
Expand Down
6 changes: 3 additions & 3 deletions benchmark/server/thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'socket'
require "socket"

port = Integer(ARGV.pop || 9090)
server = TCPServer.new('localhost', port)
server = TCPServer.new("localhost", port)

loop do
peer = server.accept
Expand Down
4 changes: 2 additions & 2 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

$LOAD_PATH << ::File.expand_path("../ext", __dir__)
Warning[:experimental] = false

require 'covered/sus'
require "covered/sus"
include Covered::Sus
8 changes: 4 additions & 4 deletions examples/compare_interrupt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'io/event'
require 'fiber'
require 'benchmark'
require "io/event"
require "fiber"
require "benchmark"

Thread.report_on_exception = true

Expand Down
8 changes: 4 additions & 4 deletions examples/handle_interrupt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'io/event'
require 'fiber'
require 'benchmark'
require "io/event"
require "fiber"
require "benchmark"

count = 0

Expand Down
6 changes: 3 additions & 3 deletions examples/interrupt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'fiber'
require '../lib/event'
require "fiber"
require "../lib/event"

th = Thread.new do
selector = Event::Selector.new(Fiber.current)
Expand Down
10 changes: 5 additions & 5 deletions examples/scheduler/scheduler.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'io/event'
require 'timers'
require 'resolv'
require "io/event"
require "timers"
require "resolv"

class IO
module Event
Expand Down Expand Up @@ -209,7 +209,7 @@ def run_once(timeout = nil)

# Run the reactor until all tasks are finished. Proxies arguments to {#async} immediately before entering the loop, if a block is provided.
def run
Kernel.raise(RuntimeError, 'Reactor has been closed') if @selector.nil?
Kernel.raise(RuntimeError, "Reactor has been closed") if @selector.nil?

Thread.handle_interrupt(Errno::EINTR => :never, Interrupt => :never) do
while self.run_once
Expand Down
8 changes: 4 additions & 4 deletions examples/scheduler/scheduler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'scheduler'
require_relative "scheduler"

RSpec.shared_examples_for IO::Event::Scheduler do
subject(:scheduler) {IO::Event::Scheduler.new(selector)}
Expand All @@ -17,7 +17,7 @@
thread.join
end

it 'can run several fibers' do
it "can run several fibers" do
sum = 0

fibers = 3.times.map do |i|
Expand All @@ -29,7 +29,7 @@
expect(sum).to be == 3
end

it 'can join threads' do
it "can join threads" do
Fiber.schedule do
1000.times do
thread = ::Thread.new do
Expand Down
22 changes: 11 additions & 11 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

return if RUBY_DESCRIPTION =~ /jruby/

require 'mkmf'
require "mkmf"

gem_name = File.basename(__dir__)
extension_name = 'IO_Event'
extension_name = "IO_Event"

# dir_config(extension_name)

$CFLAGS << " -Wall -Wno-unknown-pragmas -std=c99"

if ENV.key?('RUBY_DEBUG')
if ENV.key?("RUBY_DEBUG")
$CFLAGS << " -DRUBY_DEBUG -O0"

# Add address and undefined behaviour sanitizers:
Expand All @@ -28,24 +28,24 @@
$VPATH << "$(srcdir)/io/event"
$VPATH << "$(srcdir)/io/event/selector"

have_func('rb_ext_ractor_safe')
have_func('&rb_fiber_transfer')
have_func("rb_ext_ractor_safe")
have_func("&rb_fiber_transfer")

if have_library('uring') and have_header('liburing.h')
if have_library("uring") and have_header("liburing.h")
$srcs << "io/event/selector/uring.c"
end

if have_header('sys/epoll.h')
if have_header("sys/epoll.h")
$srcs << "io/event/selector/epoll.c"
end

if have_header('sys/event.h')
if have_header("sys/event.h")
$srcs << "io/event/selector/kqueue.c"
end

have_header('sys/wait.h')
have_header("sys/wait.h")

have_header('sys/eventfd.h')
have_header("sys/eventfd.h")
$srcs << "io/event/interrupt.c"

have_func("rb_io_descriptor")
Expand All @@ -54,7 +54,7 @@
have_func("&rb_fiber_raise")
have_func("epoll_pwait2")

have_header('ruby/io/buffer.h')
have_header("ruby/io/buffer.h")

create_header

Expand Down
4 changes: 2 additions & 2 deletions gems.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand Down
Loading

0 comments on commit 0fe638b

Please sign in to comment.