cool.io 1.7.1 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +53 -0
- data/README.md +43 -40
- data/Rakefile +1 -1
- data/cool.io.gemspec +1 -1
- data/ext/cool.io/extconf.rb +1 -0
- data/ext/cool.io/iowatcher.c +11 -6
- data/ext/iobuffer/extconf.rb +1 -0
- data/ext/iobuffer/iobuffer.c +14 -4
- data/ext/libev/ev.c +2 -2
- data/lib/cool.io/dns_resolver.rb +1 -1
- data/lib/cool.io/version.rb +1 -1
- data/spec/dns_spec.rb +8 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 963110b3477915c06d5122e46b0f92bb1ec3027ad61fa61bb19a4cfdb14f711c
|
4
|
+
data.tar.gz: f60f872be0ec258fc9ba31ac0ece2a7f8dd5be4c34306f4ecd9cd74c6597a210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc856dadd22e6a5c8ef8d19be3e7c8e62d23ca5d77ebfb07724594fa985dd16883559c4c6b5a813754b8604c2b9ffb2adee5114db79c0ef2986807fdf6e4d586
|
7
|
+
data.tar.gz: ebf278654c250395cacba0b0b11552303fffed6d5e2b002b4637eaa68723183be401aa2d7e8485f473b979708232a9e3a1d0be18f094dc6a4c3eea65be4e848f
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
permissions:
|
6
|
+
contents: read
|
7
|
+
|
8
|
+
env:
|
9
|
+
CONSOLE_OUTPUT: XTerm
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
name: ${{matrix.ruby}} on ${{matrix.os}}
|
14
|
+
runs-on: ${{matrix.os}}-latest
|
15
|
+
continue-on-error: ${{matrix.experimental}}
|
16
|
+
|
17
|
+
strategy:
|
18
|
+
fail-fast: false
|
19
|
+
matrix:
|
20
|
+
os:
|
21
|
+
- ubuntu
|
22
|
+
- macos
|
23
|
+
- windows
|
24
|
+
|
25
|
+
ruby:
|
26
|
+
- "3.0"
|
27
|
+
- "3.1"
|
28
|
+
- "3.2"
|
29
|
+
- "head"
|
30
|
+
|
31
|
+
experimental: [false]
|
32
|
+
|
33
|
+
# include:
|
34
|
+
# - os: ubuntu
|
35
|
+
# ruby: truffleruby
|
36
|
+
# experimental: true
|
37
|
+
# - os: ubuntu
|
38
|
+
# ruby: jruby
|
39
|
+
# experimental: true
|
40
|
+
# - os: ubuntu
|
41
|
+
# ruby: head
|
42
|
+
# experimental: true
|
43
|
+
|
44
|
+
steps:
|
45
|
+
- uses: actions/checkout@v3
|
46
|
+
- uses: ruby/setup-ruby@v1
|
47
|
+
with:
|
48
|
+
ruby-version: ${{matrix.ruby}}
|
49
|
+
bundler-cache: true
|
50
|
+
|
51
|
+
- name: Run tests
|
52
|
+
timeout-minutes: 2
|
53
|
+
run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
Cool.io
|
2
2
|
=======
|
3
3
|
|
4
|
-
### If you are interested in Celluloid based IO framework, please check out [Celluloid::IO](http://github.com/celluloid/celluloid-io)
|
5
|
-
|
6
4
|
Cool.io is an event library for Ruby, built on the libev event library which
|
7
5
|
provides a cross-platform interface to high performance system calls . This
|
8
6
|
includes the epoll system call for Linux, the kqueue system call for BSDs and
|
@@ -14,8 +12,9 @@ applications.
|
|
14
12
|
|
15
13
|
You can include Cool.io in your programs with:
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
```ruby
|
16
|
+
require 'cool.io'
|
17
|
+
```
|
19
18
|
|
20
19
|
Anatomy
|
21
20
|
-------
|
@@ -91,29 +90,31 @@ Example Program
|
|
91
90
|
|
92
91
|
Cool.io provides a Sinatra-like DSL for authoring event-driven programs:
|
93
92
|
|
94
|
-
|
95
|
-
|
93
|
+
```ruby
|
94
|
+
require 'cool.io'
|
95
|
+
require 'cool.io/dsl'
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
ADDR = '127.0.0.1'
|
98
|
+
PORT = 4321
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
cool.io.connection :echo_server_connection do
|
101
|
+
on_connect do
|
102
|
+
puts "#{remote_addr}:#{remote_port} connected"
|
103
|
+
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
on_close do
|
106
|
+
puts "#{remote_addr}:#{remote_port} disconnected"
|
107
|
+
end
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
on_read do |data|
|
110
|
+
write data
|
111
|
+
end
|
112
|
+
end
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
puts "Echo server listening on #{ADDR}:#{PORT}"
|
115
|
+
cool.io.server ADDR, PORT, :echo_server_connection
|
116
|
+
cool.io.run
|
117
|
+
```
|
117
118
|
|
118
119
|
This creates a new connection class called :echo_server_connection and defines
|
119
120
|
a set of callbacks for when various events occur.
|
@@ -131,29 +132,31 @@ Using Cool.io subclasses directly
|
|
131
132
|
Below is an example of how to write an echo server using a subclass instead of
|
132
133
|
the DSL:
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
```ruby
|
136
|
+
require 'cool.io'
|
137
|
+
HOST = 'localhost'
|
138
|
+
PORT = 4321
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
140
|
+
class EchoServerConnection < Cool.io::TCPSocket
|
141
|
+
def on_connect
|
142
|
+
puts "#{remote_addr}:#{remote_port} connected"
|
143
|
+
end
|
142
144
|
|
143
|
-
|
144
|
-
|
145
|
-
|
145
|
+
def on_close
|
146
|
+
puts "#{remote_addr}:#{remote_port} disconnected"
|
147
|
+
end
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
149
|
+
def on_read(data)
|
150
|
+
write data
|
151
|
+
end
|
152
|
+
end
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
+
server = Cool.io::TCPServer.new(HOST, PORT, EchoServerConnection)
|
155
|
+
server.attach(Cool.io::Loop.default)
|
154
156
|
|
155
|
-
|
156
|
-
|
157
|
+
puts "Echo server listening on #{HOST}:#{PORT}"
|
158
|
+
Cool.io::Loop.default.run
|
159
|
+
```
|
157
160
|
|
158
161
|
Here a new observer type (EchoServerConnection) is made by subclassing an
|
159
162
|
existing one and adding new implementations to existing event handlers.
|
data/Rakefile
CHANGED
@@ -48,7 +48,7 @@ namespace :build do
|
|
48
48
|
task :windows do
|
49
49
|
require 'rake_compiler_dock'
|
50
50
|
RakeCompilerDock.sh <<-CROSS
|
51
|
-
bundle && bundle exec rake cross native gem RUBY_CC_VERSION='2.7.0:2.6.0:2.5.0:2.4.0'
|
51
|
+
bundle && bundle exec rake cross native gem RUBY_CC_VERSION='3.0.0:2.7.0:2.6.0:2.5.0:2.4.0'
|
52
52
|
CROSS
|
53
53
|
end
|
54
54
|
end
|
data/cool.io.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Coolio::VERSION
|
8
8
|
s.authors = ["Tony Arcieri", "Masahiro Nakagawa"]
|
9
9
|
s.email = ["tony.arcieri@gmail.com", "repeatedly@gmail.com"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://github.com/socketry/cool.io"
|
11
11
|
s.summary = "A cool framework for doing high performance I/O in Ruby"
|
12
12
|
s.description = "Cool.io provides a high performance event framework for Ruby which uses the libev C library"
|
13
13
|
s.extensions = ["ext/cool.io/extconf.rb", "ext/iobuffer/extconf.rb"]
|
data/ext/cool.io/extconf.rb
CHANGED
data/ext/cool.io/iowatcher.c
CHANGED
@@ -65,11 +65,6 @@ static VALUE Coolio_IOWatcher_initialize(int argc, VALUE *argv, VALUE self)
|
|
65
65
|
char *flags_str;
|
66
66
|
int events;
|
67
67
|
struct Coolio_Watcher *watcher_data;
|
68
|
-
#if HAVE_RB_IO_T
|
69
|
-
rb_io_t *fptr;
|
70
|
-
#else
|
71
|
-
OpenFile *fptr;
|
72
|
-
#endif
|
73
68
|
|
74
69
|
rb_scan_args(argc, argv, "11", &io, &flags);
|
75
70
|
|
@@ -88,10 +83,20 @@ static VALUE Coolio_IOWatcher_initialize(int argc, VALUE *argv, VALUE self)
|
|
88
83
|
rb_raise(rb_eArgError, "invalid event type: '%s' (must be 'r', 'w', or 'rw')", flags_str);
|
89
84
|
|
90
85
|
Data_Get_Struct(self, struct Coolio_Watcher, watcher_data);
|
91
|
-
|
86
|
+
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
92
87
|
|
93
88
|
watcher_data->dispatch_callback = Coolio_IOWatcher_dispatch_callback;
|
89
|
+
#ifdef HAVE_RB_IO_DESCRIPTOR
|
90
|
+
ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, rb_io_descriptor(io), events);
|
91
|
+
#else
|
92
|
+
#if defined(HAVE_RB_IO_T)
|
93
|
+
rb_io_t *fptr;
|
94
|
+
#else
|
95
|
+
OpenFile *fptr;
|
96
|
+
#endif
|
97
|
+
GetOpenFile(io, fptr);
|
94
98
|
ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, FPTR_TO_FD(fptr), events);
|
99
|
+
#endif
|
95
100
|
watcher_data->event_types.ev_io.data = (void *)self;
|
96
101
|
|
97
102
|
return Qnil;
|
data/ext/iobuffer/extconf.rb
CHANGED
data/ext/iobuffer/iobuffer.c
CHANGED
@@ -378,17 +378,22 @@ IO_Buffer_read_from(VALUE self, VALUE io)
|
|
378
378
|
{
|
379
379
|
struct buffer *buf;
|
380
380
|
int ret;
|
381
|
-
#if HAVE_RB_IO_T
|
381
|
+
#if defined(HAVE_RB_IO_T) || defined(HAVE_RB_IO_DESCRIPTOR)
|
382
382
|
rb_io_t *fptr;
|
383
383
|
#else
|
384
384
|
OpenFile *fptr;
|
385
385
|
#endif
|
386
386
|
|
387
387
|
Data_Get_Struct(self, struct buffer, buf);
|
388
|
-
|
388
|
+
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
389
|
+
GetOpenFile(io, fptr);
|
389
390
|
rb_io_set_nonblock(fptr);
|
390
391
|
|
392
|
+
#ifdef HAVE_RB_IO_DESCRIPTOR
|
393
|
+
ret = buffer_read_from(buf, rb_io_descriptor(io));
|
394
|
+
#else
|
391
395
|
ret = buffer_read_from(buf, FPTR_TO_FD(fptr));
|
396
|
+
#endif
|
392
397
|
return ret == -1 ? Qnil : INT2NUM(ret);
|
393
398
|
}
|
394
399
|
|
@@ -404,17 +409,22 @@ static VALUE
|
|
404
409
|
IO_Buffer_write_to(VALUE self, VALUE io)
|
405
410
|
{
|
406
411
|
struct buffer *buf;
|
407
|
-
#if HAVE_RB_IO_T
|
412
|
+
#if defined(HAVE_RB_IO_T) || defined(HAVE_RB_IO_DESCRIPTOR)
|
408
413
|
rb_io_t *fptr;
|
409
414
|
#else
|
410
415
|
OpenFile *fptr;
|
411
416
|
#endif
|
412
417
|
|
413
418
|
Data_Get_Struct(self, struct buffer, buf);
|
414
|
-
|
419
|
+
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
420
|
+
GetOpenFile(io, fptr);
|
415
421
|
rb_io_set_nonblock(fptr);
|
416
422
|
|
423
|
+
#ifdef HAVE_RB_IO_DESCRIPTOR
|
424
|
+
return INT2NUM(buffer_write_to(buf, rb_io_descriptor(io)));
|
425
|
+
#else
|
417
426
|
return INT2NUM(buffer_write_to(buf, FPTR_TO_FD(fptr)));
|
427
|
+
#endif
|
418
428
|
}
|
419
429
|
|
420
430
|
/*
|
data/ext/libev/ev.c
CHANGED
@@ -2481,7 +2481,7 @@ evpipe_write (EV_P_ EV_ATOMIC_T *flag)
|
|
2481
2481
|
#ifdef _WIN32
|
2482
2482
|
WSABUF buf;
|
2483
2483
|
DWORD sent;
|
2484
|
-
buf.buf = &buf;
|
2484
|
+
buf.buf = (char *)&buf;
|
2485
2485
|
buf.len = 1;
|
2486
2486
|
WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
|
2487
2487
|
#else
|
@@ -3768,7 +3768,7 @@ rb_thread_unsafe_dangerous_crazy_blocking_region_end(...);
|
|
3768
3768
|
#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
|
3769
3769
|
poll_args.loop = loop;
|
3770
3770
|
poll_args.waittime = waittime;
|
3771
|
-
rb_thread_call_without_gvl(ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
|
3771
|
+
rb_thread_call_without_gvl((void *)ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
|
3772
3772
|
#else
|
3773
3773
|
backend_poll (EV_A_ waittime);
|
3774
3774
|
#endif
|
data/lib/cool.io/dns_resolver.rb
CHANGED
@@ -49,7 +49,7 @@ module Coolio
|
|
49
49
|
entries.each { |e| hosts[e] ||= addr }
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
unless hosts.key?("localhost")
|
53
53
|
# On Windows, there is a case that hosts file doesn't have entry by default
|
54
54
|
# and preferred IPv4/IPv6 behavior may be changed by registry key [1], so
|
55
55
|
# "localhost" should be resolved by getaddrinfo.
|
data/lib/cool.io/version.rb
CHANGED
data/spec/dns_spec.rb
CHANGED
@@ -47,4 +47,12 @@ describe "DNS" do
|
|
47
47
|
expect( Coolio::DNSResolver.hosts("localhost", file.path)).to eq @preferred_localhost_address
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
it "resolve missing localhost even though hosts entries exist" do
|
52
|
+
Tempfile.open("empty") do |file|
|
53
|
+
file.puts("127.0.0.1 example.internal")
|
54
|
+
file.flush
|
55
|
+
expect( Coolio::DNSResolver.hosts("localhost", file.path)).to eq @preferred_localhost_address
|
56
|
+
end
|
57
|
+
end
|
50
58
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cool.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
- Masahiro Nakagawa
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -78,6 +78,7 @@ extensions:
|
|
78
78
|
- ext/iobuffer/extconf.rb
|
79
79
|
extra_rdoc_files: []
|
80
80
|
files:
|
81
|
+
- ".github/workflows/test.yaml"
|
81
82
|
- ".gitignore"
|
82
83
|
- ".rspec"
|
83
84
|
- ".travis.yml"
|
@@ -153,11 +154,11 @@ files:
|
|
153
154
|
- spec/udp_socket_spec.rb
|
154
155
|
- spec/unix_listener_spec.rb
|
155
156
|
- spec/unix_server_spec.rb
|
156
|
-
homepage:
|
157
|
+
homepage: https://github.com/socketry/cool.io
|
157
158
|
licenses:
|
158
159
|
- MIT
|
159
160
|
metadata: {}
|
160
|
-
post_install_message:
|
161
|
+
post_install_message:
|
161
162
|
rdoc_options: []
|
162
163
|
require_paths:
|
163
164
|
- lib
|
@@ -172,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
- !ruby/object:Gem::Version
|
173
174
|
version: '0'
|
174
175
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
-
signing_key:
|
176
|
+
rubygems_version: 3.5.3
|
177
|
+
signing_key:
|
177
178
|
specification_version: 4
|
178
179
|
summary: A cool framework for doing high performance I/O in Ruby
|
179
180
|
test_files:
|