nio4r 0.2.0 → 2.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/ext/libev/Changes +232 -3
- data/ext/libev/LICENSE +2 -1
- data/ext/libev/README +11 -10
- data/ext/libev/ev.c +2249 -473
- data/ext/libev/ev.h +165 -135
- data/ext/libev/ev_epoll.c +68 -36
- data/ext/libev/ev_iouring.c +694 -0
- data/ext/libev/ev_kqueue.c +44 -18
- data/ext/libev/ev_linuxaio.c +620 -0
- data/ext/libev/ev_poll.c +28 -20
- data/ext/libev/ev_port.c +23 -10
- data/ext/libev/ev_select.c +18 -12
- data/ext/libev/ev_vars.h +65 -19
- data/ext/libev/ev_win32.c +16 -7
- data/ext/libev/ev_wrap.h +236 -160
- data/ext/nio4r/.clang-format +16 -0
- data/ext/nio4r/bytebuffer.c +465 -0
- data/ext/nio4r/extconf.rb +44 -35
- data/ext/nio4r/libev.h +3 -4
- data/ext/nio4r/monitor.c +186 -54
- data/ext/nio4r/nio4r.h +17 -23
- data/ext/nio4r/nio4r_ext.c +11 -3
- data/ext/nio4r/org/nio4r/ByteBuffer.java +295 -0
- data/ext/nio4r/org/nio4r/Monitor.java +176 -0
- data/ext/nio4r/org/nio4r/Nio4r.java +104 -0
- data/ext/nio4r/org/nio4r/Selector.java +297 -0
- data/ext/nio4r/selector.c +350 -182
- data/lib/nio/bytebuffer.rb +235 -0
- data/lib/nio/monitor.rb +100 -8
- data/lib/nio/selector.rb +110 -44
- data/lib/nio/version.rb +8 -1
- data/lib/nio.rb +47 -16
- data/lib/nio4r.rb +7 -0
- data/license.md +80 -0
- data/readme.md +91 -0
- data/releases.md +343 -0
- data.tar.gz.sig +2 -0
- metadata +114 -79
- metadata.gz.sig +0 -0
- data/.gitignore +0 -20
- data/.rspec +0 -4
- data/.travis.yml +0 -7
- data/CHANGES.md +0 -10
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -20
- data/README.md +0 -171
- data/Rakefile +0 -9
- data/examples/echo_server.rb +0 -38
- data/ext/libev/README.embed +0 -3
- data/ext/libev/test_libev_win32.c +0 -123
- data/lib/nio/jruby/monitor.rb +0 -42
- data/lib/nio/jruby/selector.rb +0 -135
- data/nio4r.gemspec +0 -22
- data/spec/nio/monitor_spec.rb +0 -46
- data/spec/nio/selector_spec.rb +0 -269
- data/spec/spec_helper.rb +0 -3
- data/tasks/extension.rake +0 -10
- data/tasks/rspec.rake +0 -7
metadata
CHANGED
|
@@ -1,125 +1,160 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nio4r
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 2.7.5
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Tony Arcieri
|
|
9
|
-
|
|
8
|
+
- Samuel Williams
|
|
9
|
+
- Olle Jonsson
|
|
10
|
+
- Gregory Longtin
|
|
11
|
+
- Tiago Cardoso
|
|
12
|
+
- Joao Fernandes
|
|
13
|
+
- Thomas Dziedzic
|
|
14
|
+
- Boaz Segev
|
|
15
|
+
- Logan Bowers
|
|
16
|
+
- Pedro Paiva
|
|
17
|
+
- Jun Aruga
|
|
18
|
+
- Omer Katz
|
|
19
|
+
- Upekshe Jayasekera
|
|
20
|
+
- Tim Carey-Smith
|
|
21
|
+
- Benoit Daloze
|
|
22
|
+
- Sergey Avseyev
|
|
23
|
+
- Tomoya Ishida
|
|
24
|
+
- Usaku Nakamura
|
|
25
|
+
- Cédric Boutillier
|
|
26
|
+
- Daniel Berger
|
|
27
|
+
- Dirkjan Bussink
|
|
28
|
+
- Hiroshi Shibata
|
|
29
|
+
- Jesús Burgos Maciá
|
|
30
|
+
- Luis Lavena
|
|
31
|
+
- Pavel Rosický
|
|
32
|
+
- Sadayuki Furuhashi
|
|
33
|
+
- Stephen von Takach
|
|
34
|
+
- Vladimir Kochnev
|
|
35
|
+
- Vít Ondruch
|
|
36
|
+
- Anatol Pomozov
|
|
37
|
+
- Bernd Ahlers
|
|
38
|
+
- Charles Oliver Nutter
|
|
39
|
+
- Denis Washington
|
|
40
|
+
- Elad Eyal
|
|
41
|
+
- Jean byroot Boussier
|
|
42
|
+
- Jeffrey Martin
|
|
43
|
+
- John Thornton
|
|
44
|
+
- Jun Jiang
|
|
45
|
+
- Lars Kanis
|
|
46
|
+
- Marek Kowalcze
|
|
47
|
+
- Maxime Demolin
|
|
48
|
+
- Orien Madgwick
|
|
49
|
+
- Pavel Lobashov
|
|
50
|
+
- Per Lundberg
|
|
51
|
+
- Phillip Aldridge
|
|
52
|
+
- Ravil Bayramgalin
|
|
53
|
+
- Shannon Skipper
|
|
54
|
+
- Tao Luo
|
|
55
|
+
- Thomas Kuntz
|
|
56
|
+
- Tsimnuj Hawj
|
|
57
|
+
- Zhang Kang
|
|
10
58
|
bindir: bin
|
|
11
|
-
cert_chain:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
version: 2.7.0
|
|
44
|
-
type: :development
|
|
45
|
-
prerelease: false
|
|
46
|
-
version_requirements: *70186951375540
|
|
47
|
-
description: New IO for Ruby
|
|
48
|
-
email:
|
|
49
|
-
- tony.arcieri@gmail.com
|
|
59
|
+
cert_chain:
|
|
60
|
+
- |
|
|
61
|
+
-----BEGIN CERTIFICATE-----
|
|
62
|
+
MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
|
|
63
|
+
ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
|
|
64
|
+
CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
|
|
65
|
+
MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
|
|
66
|
+
MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
|
|
67
|
+
bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
|
|
68
|
+
igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
|
|
69
|
+
9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
|
|
70
|
+
sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
|
|
71
|
+
e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
|
|
72
|
+
XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
|
|
73
|
+
RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
|
|
74
|
+
tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
|
|
75
|
+
zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
|
|
76
|
+
xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
|
77
|
+
BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
|
|
78
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
|
|
79
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
|
|
80
|
+
cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
|
|
81
|
+
xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
|
|
82
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
|
83
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
|
84
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
|
85
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
|
86
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
|
87
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
|
88
|
+
-----END CERTIFICATE-----
|
|
89
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
90
|
+
dependencies: []
|
|
50
91
|
executables: []
|
|
51
92
|
extensions:
|
|
52
93
|
- ext/nio4r/extconf.rb
|
|
53
94
|
extra_rdoc_files: []
|
|
54
95
|
files:
|
|
55
|
-
- .gitignore
|
|
56
|
-
- .rspec
|
|
57
|
-
- .travis.yml
|
|
58
|
-
- CHANGES.md
|
|
59
|
-
- Gemfile
|
|
60
|
-
- LICENSE.txt
|
|
61
|
-
- README.md
|
|
62
|
-
- Rakefile
|
|
63
|
-
- examples/echo_server.rb
|
|
64
96
|
- ext/libev/Changes
|
|
65
97
|
- ext/libev/LICENSE
|
|
66
98
|
- ext/libev/README
|
|
67
|
-
- ext/libev/README.embed
|
|
68
99
|
- ext/libev/ev.c
|
|
69
100
|
- ext/libev/ev.h
|
|
70
101
|
- ext/libev/ev_epoll.c
|
|
102
|
+
- ext/libev/ev_iouring.c
|
|
71
103
|
- ext/libev/ev_kqueue.c
|
|
104
|
+
- ext/libev/ev_linuxaio.c
|
|
72
105
|
- ext/libev/ev_poll.c
|
|
73
106
|
- ext/libev/ev_port.c
|
|
74
107
|
- ext/libev/ev_select.c
|
|
75
108
|
- ext/libev/ev_vars.h
|
|
76
109
|
- ext/libev/ev_win32.c
|
|
77
110
|
- ext/libev/ev_wrap.h
|
|
78
|
-
- ext/
|
|
111
|
+
- ext/nio4r/.clang-format
|
|
112
|
+
- ext/nio4r/bytebuffer.c
|
|
79
113
|
- ext/nio4r/extconf.rb
|
|
80
114
|
- ext/nio4r/libev.h
|
|
81
115
|
- ext/nio4r/monitor.c
|
|
82
116
|
- ext/nio4r/nio4r.h
|
|
83
117
|
- ext/nio4r/nio4r_ext.c
|
|
118
|
+
- ext/nio4r/org/nio4r/ByteBuffer.java
|
|
119
|
+
- ext/nio4r/org/nio4r/Monitor.java
|
|
120
|
+
- ext/nio4r/org/nio4r/Nio4r.java
|
|
121
|
+
- ext/nio4r/org/nio4r/Selector.java
|
|
84
122
|
- ext/nio4r/selector.c
|
|
85
123
|
- lib/nio.rb
|
|
86
|
-
- lib/nio/
|
|
87
|
-
- lib/nio/jruby/selector.rb
|
|
124
|
+
- lib/nio/bytebuffer.rb
|
|
88
125
|
- lib/nio/monitor.rb
|
|
89
126
|
- lib/nio/selector.rb
|
|
90
127
|
- lib/nio/version.rb
|
|
91
|
-
- nio4r.
|
|
92
|
-
-
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
128
|
+
- lib/nio4r.rb
|
|
129
|
+
- license.md
|
|
130
|
+
- readme.md
|
|
131
|
+
- releases.md
|
|
132
|
+
homepage: https://github.com/socketry/nio4r
|
|
133
|
+
licenses:
|
|
134
|
+
- MIT
|
|
135
|
+
- BSD-2-Clause
|
|
136
|
+
metadata:
|
|
137
|
+
bug_tracker_uri: https://github.com/socketry/nio4r/issues
|
|
138
|
+
changelog_uri: https://github.com/socketry/nio4r/blob/main/releases.md
|
|
139
|
+
documentation_uri: https://www.rubydoc.info/gems/nio4r
|
|
140
|
+
funding_uri: https://github.com/sponsors/ioquatix/
|
|
141
|
+
source_code_uri: https://github.com/socketry/nio4r.git
|
|
142
|
+
wiki_uri: https://github.com/socketry/nio4r/wiki
|
|
100
143
|
rdoc_options: []
|
|
101
144
|
require_paths:
|
|
102
145
|
- lib
|
|
103
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
|
-
none: false
|
|
105
147
|
requirements:
|
|
106
|
-
- -
|
|
148
|
+
- - ">="
|
|
107
149
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '
|
|
150
|
+
version: '2.6'
|
|
109
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
-
none: false
|
|
111
152
|
requirements:
|
|
112
|
-
- -
|
|
153
|
+
- - ">="
|
|
113
154
|
- !ruby/object:Gem::Version
|
|
114
155
|
version: '0'
|
|
115
156
|
requirements: []
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
summary: NIO provides a high performance selector API for monitoring IO objects
|
|
121
|
-
test_files:
|
|
122
|
-
- spec/nio/monitor_spec.rb
|
|
123
|
-
- spec/nio/selector_spec.rb
|
|
124
|
-
- spec/spec_helper.rb
|
|
125
|
-
has_rdoc:
|
|
157
|
+
rubygems_version: 3.7.2
|
|
158
|
+
specification_version: 4
|
|
159
|
+
summary: New IO for Ruby
|
|
160
|
+
test_files: []
|
metadata.gz.sig
ADDED
|
Binary file
|
data/.gitignore
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
*.gem
|
|
2
|
-
*.rbc
|
|
3
|
-
.bundle
|
|
4
|
-
.config
|
|
5
|
-
.yardoc
|
|
6
|
-
Gemfile.lock
|
|
7
|
-
InstalledFiles
|
|
8
|
-
_yardoc
|
|
9
|
-
coverage
|
|
10
|
-
doc/
|
|
11
|
-
lib/bundler/man
|
|
12
|
-
pkg
|
|
13
|
-
rdoc
|
|
14
|
-
spec/reports
|
|
15
|
-
test/tmp
|
|
16
|
-
test/version_tmp
|
|
17
|
-
tmp
|
|
18
|
-
lib/nio4r_ext.*
|
|
19
|
-
ext/**/*.o
|
|
20
|
-
ext/**/nio4r_ext.*
|
data/.rspec
DELETED
data/.travis.yml
DELETED
data/CHANGES.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
0.2.0
|
|
2
|
-
-----
|
|
3
|
-
* NIO::Monitor#readiness API to query readiness, along with #readable? and
|
|
4
|
-
#writable? helper methods
|
|
5
|
-
* NIO::Selector#select_each API which avoids memory allocations if possible
|
|
6
|
-
* Bugfixes for the JRuby implementation
|
|
7
|
-
|
|
8
|
-
0.1.0
|
|
9
|
-
-----
|
|
10
|
-
* Initial release. Merry Christmas!
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2011 Tony Arcieri
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
New IO for Ruby
|
|
2
|
-
===============
|
|
3
|
-
[](http://travis-ci.org/tarcieri/nio4r)
|
|
4
|
-
|
|
5
|
-
When it comes to managing many IO objects on Ruby, there aren't a whole lot of
|
|
6
|
-
options. The most powerful API Ruby itself gives you is Kernel.select, and
|
|
7
|
-
select is hurting when it comes to performance and in terms of having a nice
|
|
8
|
-
API.
|
|
9
|
-
|
|
10
|
-
Once upon a time Java was a similar mess. They got out of it by adding the
|
|
11
|
-
Java NIO API. Java NIO provides a high performance selector API for monitoring
|
|
12
|
-
large numbers of file descriptors.
|
|
13
|
-
|
|
14
|
-
This library aims to incorporate the ideas of Java NIO in Ruby. These are:
|
|
15
|
-
|
|
16
|
-
* Expose high level interfaces for doing high performance IO, but keep the
|
|
17
|
-
codebase small to encourage multiple implementations on different platforms
|
|
18
|
-
* Be as portable as possible, in this case across several Ruby VMs
|
|
19
|
-
* Provide inherently thread-safe facilities for working with IO objects
|
|
20
|
-
|
|
21
|
-
Supported Platforms
|
|
22
|
-
-------------------
|
|
23
|
-
|
|
24
|
-
nio4r is known to work on the following Ruby implementations:
|
|
25
|
-
|
|
26
|
-
* MRI/YARV 1.8.7, 1.9.2, 1.9.3
|
|
27
|
-
* JRuby 1.6.x (and likely earlier versions too)
|
|
28
|
-
* Rubinius 1.x/2.0
|
|
29
|
-
* A pure Ruby implementation based on Kernel.select is also provided
|
|
30
|
-
|
|
31
|
-
Platform notes:
|
|
32
|
-
|
|
33
|
-
* MRI/YARV and Rubinius implement nio4j with a C extension based on libev,
|
|
34
|
-
which provides a high performance binding to native IO APIs
|
|
35
|
-
* JRuby uses a special backend based on the high performance Java NIO subsystem
|
|
36
|
-
* A pure Ruby implementation is also provided for Ruby implementations which
|
|
37
|
-
don't implement the MRI C extension API
|
|
38
|
-
|
|
39
|
-
Usage
|
|
40
|
-
-----
|
|
41
|
-
|
|
42
|
-
### Selectors
|
|
43
|
-
|
|
44
|
-
The NIO::Selector class is the main API provided by nio4r. Use it where you
|
|
45
|
-
might otherwise use Kernel.select, but want to monitor the same set of IO
|
|
46
|
-
objects across multiple select calls rather than having to reregister them
|
|
47
|
-
every single time:
|
|
48
|
-
|
|
49
|
-
```ruby
|
|
50
|
-
require 'nio'
|
|
51
|
-
|
|
52
|
-
selector = NIO::Selector.new
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
To monitor IO objects, attach them to the selector with the NIO::Selector#register
|
|
56
|
-
method, monitoring them for read readiness with the :r parameter, write
|
|
57
|
-
readiness with the :w parameter, or both with :rw.
|
|
58
|
-
|
|
59
|
-
```ruby
|
|
60
|
-
>> reader, writer = IO.pipe
|
|
61
|
-
=> [#<IO:0xf30>, #<IO:0xf34>]
|
|
62
|
-
>> monitor = selector.register(reader, :r)
|
|
63
|
-
=> #<NIO::Monitor:0xfbc>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
After registering an IO object with the selector, you'll get a NIO::Monitor
|
|
67
|
-
object which you can use for managing how a particular IO object is being
|
|
68
|
-
monitored. Monitors will store an arbitrary value of your choice, which
|
|
69
|
-
provides an easy way to implement callbacks:
|
|
70
|
-
|
|
71
|
-
```ruby
|
|
72
|
-
>> monitor = selector.register(reader, :r)
|
|
73
|
-
=> #<NIO::Monitor:0xfbc>
|
|
74
|
-
>> monitor.value = proc { puts "Got some data: #{monitor.io.read_nonblock(4096)}" }
|
|
75
|
-
=> #<Proc:0x1000@(irb):4>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
The main method of importance is NIO::Selector#select, which monitors all
|
|
79
|
-
registered IO objects and returns an array of monitors that are ready.
|
|
80
|
-
|
|
81
|
-
```ruby
|
|
82
|
-
>> writer << "Hi there!"
|
|
83
|
-
=> #<IO:0x103c>
|
|
84
|
-
>> ready = selector.select
|
|
85
|
-
=> [#<NIO::Monitor:0xfbc>]
|
|
86
|
-
>> ready.each { |m| m.value.call }
|
|
87
|
-
Got some data: Hi there!
|
|
88
|
-
=> [#<NIO::Monitor:0xfbc>]
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
By default, NIO::Selector#select will block indefinitely until one of the IO
|
|
92
|
-
objects being monitored becomes ready. However, you can also pass a timeout to
|
|
93
|
-
wait in seconds to NIO::Selector#select just like you can with Kernel.select:
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
ready = selector.select(15) # Wait 15 seconds
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
If a timeout occurs, ready will be nil.
|
|
100
|
-
|
|
101
|
-
You can avoid allocating an array each time you call NIO::Selector#select by
|
|
102
|
-
using NIO::Selector#select_each instead. This method successively yields ready
|
|
103
|
-
NIO::Monitor objects:
|
|
104
|
-
|
|
105
|
-
```ruby
|
|
106
|
-
>> selector.select_each { |m| m.value.call }
|
|
107
|
-
Got some data: Hi there!
|
|
108
|
-
=> 1
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
When you're done monitoring a particular IO object, just deregister it from
|
|
112
|
-
the selector:
|
|
113
|
-
|
|
114
|
-
```ruby
|
|
115
|
-
selector.deregister(reader)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Monitors
|
|
119
|
-
|
|
120
|
-
Monitors provide methods which let you introspect on why a particular IO
|
|
121
|
-
object was selected. These methods are not thread safe unless you are holding
|
|
122
|
-
the selector lock (i.e. if you're in a #select_each callback). Only use them
|
|
123
|
-
if you aren't concerned with thread safety, or you're within a #select_each
|
|
124
|
-
callback:
|
|
125
|
-
|
|
126
|
-
- ***#interests***: what this monitor is interested in (:r, :w, or :rw)
|
|
127
|
-
- ***#readiness***: what the monitored IO object is ready for according to the last select operation
|
|
128
|
-
- ***#readable?***: was the IO readable last time it was selected?
|
|
129
|
-
- ***#writable?***: was the IO writable last time it was selected?
|
|
130
|
-
|
|
131
|
-
Monitors also support a ***#value*** and ***#value=*** method for storing a
|
|
132
|
-
handle to an arbitrary object of your choice (e.g. a proc)
|
|
133
|
-
|
|
134
|
-
Concurrency
|
|
135
|
-
-----------
|
|
136
|
-
|
|
137
|
-
nio4r provides internal locking to ensure that it's safe to use from multiple
|
|
138
|
-
concurrent threads. Only one thread can select on a NIO::Selector at a given
|
|
139
|
-
time, and while a thread is selecting other threads are blocked from
|
|
140
|
-
registering or deregistering IO objects. Once a pending select has completed,
|
|
141
|
-
requests to register/unregister IO objects will be processed.
|
|
142
|
-
|
|
143
|
-
NIO::Selector#wakeup allows one thread to unblock another thread that's in the
|
|
144
|
-
middle of an NIO::Selector#select operation. This lets other threads that need
|
|
145
|
-
to communicate immediately with the selector unblock it so it can process
|
|
146
|
-
other events that it's not presently selecting on.
|
|
147
|
-
|
|
148
|
-
What nio4r is not
|
|
149
|
-
-----------------
|
|
150
|
-
|
|
151
|
-
nio4r is not a full-featured event framework like EventMachine or Cool.io.
|
|
152
|
-
Instead, nio4r is the sort of thing you might write a library like that on
|
|
153
|
-
top of. nio4r provides a minimal API such that individual Ruby implementers
|
|
154
|
-
may choose to produce optimized versions for their platform, without having
|
|
155
|
-
to maintain a large codebase. As of the time of writing, the current
|
|
156
|
-
implementation is a little over 100 lines of code for both the pure Ruby and
|
|
157
|
-
JRuby backends. The native extension uses approximately 500 lines of C code.
|
|
158
|
-
|
|
159
|
-
nio4r is also not a replacement for Kinder Gentler IO (KGIO), a set of
|
|
160
|
-
advanced Ruby IO APIs. At some point in the future nio4r might provide a
|
|
161
|
-
cross-platform implementation that uses KGIO on CRubies, and Java NIO on JRuby,
|
|
162
|
-
however this is not the case today.
|
|
163
|
-
|
|
164
|
-
License
|
|
165
|
-
-------
|
|
166
|
-
|
|
167
|
-
Copyright (c) 2011 Tony Arcieri. Distributed under the MIT License. See
|
|
168
|
-
LICENSE.txt for further details.
|
|
169
|
-
|
|
170
|
-
Includes libev. Copyright (C)2007-09 Marc Alexander Lehmann. Distributed under
|
|
171
|
-
the BSD license. See ext/libev/LICENSE for details.
|
data/Rakefile
DELETED
data/examples/echo_server.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
$:.push File.expand_path('../../lib', __FILE__)
|
|
4
|
-
require 'nio'
|
|
5
|
-
require 'socket'
|
|
6
|
-
|
|
7
|
-
class EchoServer
|
|
8
|
-
def initialize(host, port)
|
|
9
|
-
@selector = NIO::Selector.new
|
|
10
|
-
|
|
11
|
-
puts "Listening on #{host}:#{port}"
|
|
12
|
-
@server = TCPServer.new(host, port)
|
|
13
|
-
|
|
14
|
-
monitor = @selector.register(@server, :r)
|
|
15
|
-
monitor.value = proc { accept }
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def run
|
|
19
|
-
while true
|
|
20
|
-
@selector.select_each { |monitor| monitor.value.call(monitor) }
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def accept
|
|
25
|
-
socket = @server.accept
|
|
26
|
-
monitor = @selector.register(socket, :r)
|
|
27
|
-
monitor.value = proc { read(socket) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def read(socket)
|
|
31
|
-
data = socket.read_nonblock(4096)
|
|
32
|
-
socket.write_nonblock(data)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
if $0 == __FILE__
|
|
37
|
-
EchoServer.new("localhost", 1234).run
|
|
38
|
-
end
|
data/ext/libev/README.embed
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// a single header file is required
|
|
2
|
-
#include <ev.h>
|
|
3
|
-
#include <stdio.h>
|
|
4
|
-
#include <io.h>
|
|
5
|
-
|
|
6
|
-
// every watcher type has its own typedef'd struct
|
|
7
|
-
// with the name ev_TYPE
|
|
8
|
-
ev_io stdin_watcher;
|
|
9
|
-
ev_timer timeout_watcher;
|
|
10
|
-
|
|
11
|
-
// all watcher callbacks have a similar signature
|
|
12
|
-
// this callback is called when data is readable on stdin
|
|
13
|
-
static void
|
|
14
|
-
stdin_cb (EV_P_ ev_io *w, int revents)
|
|
15
|
-
{
|
|
16
|
-
puts ("stdin ready or done or something");
|
|
17
|
-
// for one-shot events, one must manually stop the watcher
|
|
18
|
-
// with its corresponding stop function.
|
|
19
|
-
//ev_io_stop (EV_A_ w);
|
|
20
|
-
|
|
21
|
-
// this causes all nested ev_loop's to stop iterating
|
|
22
|
-
//ev_unloop (EV_A_ EVUNLOOP_ALL);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// another callback, this time for a time-out
|
|
26
|
-
static void
|
|
27
|
-
timeout_cb (EV_P_ ev_timer *w, int revents)
|
|
28
|
-
{
|
|
29
|
-
puts ("timeout");
|
|
30
|
-
// this causes the innermost ev_loop to stop iterating
|
|
31
|
-
ev_unloop (EV_A_ EVUNLOOP_ONE);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#include <winsock.h>
|
|
37
|
-
|
|
38
|
-
#include <stdlib.h>
|
|
39
|
-
#include <iostream>
|
|
40
|
-
int get_server_fd()
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
//----------------------
|
|
44
|
-
// Initialize Winsock.
|
|
45
|
-
WSADATA wsaData;
|
|
46
|
-
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
|
47
|
-
if (iResult != NO_ERROR) {
|
|
48
|
-
printf("Error at WSAStartup()\n");
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
//----------------------
|
|
53
|
-
// Create a SOCKET for listening for
|
|
54
|
-
// incoming connection requests.
|
|
55
|
-
SOCKET ListenSocket;
|
|
56
|
-
ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
57
|
-
if (ListenSocket == INVALID_SOCKET) {
|
|
58
|
-
printf("Error at socket(): %ld\n", WSAGetLastError());
|
|
59
|
-
WSACleanup();
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
printf("socket returned %d\n", ListenSocket);
|
|
63
|
-
|
|
64
|
-
//----------------------
|
|
65
|
-
// The sockaddr_in structure specifies the address family,
|
|
66
|
-
// IP address, and port for the socket that is being bound.
|
|
67
|
-
sockaddr_in service;
|
|
68
|
-
service.sin_family = AF_INET;
|
|
69
|
-
service.sin_addr.s_addr = inet_addr("127.0.0.1");
|
|
70
|
-
service.sin_port = htons(4444);
|
|
71
|
-
|
|
72
|
-
if (bind( ListenSocket,
|
|
73
|
-
(SOCKADDR*) &service,
|
|
74
|
-
sizeof(service)) == SOCKET_ERROR) {
|
|
75
|
-
printf("bind() failed.\n");
|
|
76
|
-
closesocket(ListenSocket);
|
|
77
|
-
WSACleanup();
|
|
78
|
-
return 1;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
//----------------------
|
|
82
|
-
// Listen for incoming connection requests.
|
|
83
|
-
// on the created socket
|
|
84
|
-
if (listen( ListenSocket, 1 ) == SOCKET_ERROR) {
|
|
85
|
-
printf("Error listening on socket.\n");
|
|
86
|
-
closesocket(ListenSocket);
|
|
87
|
-
WSACleanup();
|
|
88
|
-
return 1;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
printf("sock and osf handle are %d %d, error is \n", ListenSocket, _get_osfhandle (ListenSocket)); // -1 is invalid file handle: http://msdn.microsoft.com/en-us/library/ks2530z6.aspx
|
|
93
|
-
printf("err was %d\n", WSAGetLastError());
|
|
94
|
-
//----------------------
|
|
95
|
-
return ListenSocket;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
int
|
|
100
|
-
main (void)
|
|
101
|
-
{
|
|
102
|
-
struct ev_loop *loopy = ev_default_loop(0);
|
|
103
|
-
int fd = get_server_fd();
|
|
104
|
-
int fd_real = _open_osfhandle(fd, NULL);
|
|
105
|
-
int conv = _get_osfhandle(fd_real);
|
|
106
|
-
printf("got server fd %d, loop %d, fd_real %d, that converted %d\n", fd, loopy, fd_real, conv);
|
|
107
|
-
// accept(fd, NULL, NULL);
|
|
108
|
-
// initialise an io watcher, then start it
|
|
109
|
-
// this one will watch for stdin to become readable
|
|
110
|
-
ev_io_init (&stdin_watcher, stdin_cb, /*STDIN_FILENO*/ conv, EV_READ);
|
|
111
|
-
ev_io_start (loopy, &stdin_watcher);
|
|
112
|
-
|
|
113
|
-
// initialise a timer watcher, then start it
|
|
114
|
-
// simple non-repeating 5.5 second timeout
|
|
115
|
-
//ev_timer_init (&timeout_watcher, timeout_cb, 15.5, 0.);
|
|
116
|
-
//ev_timer_start (loopy, &timeout_watcher);
|
|
117
|
-
printf("starting loop\n");
|
|
118
|
-
// now wait for events to arrive
|
|
119
|
-
ev_loop (loopy, 0);
|
|
120
|
-
|
|
121
|
-
// unloop was called, so exit
|
|
122
|
-
return 0;
|
|
123
|
-
}
|