nio4r 2.0.0.pre-java → 2.1.0-java
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 +4 -4
- data/.rspec +0 -1
- data/.rubocop.yml +31 -38
- data/.ruby-version +1 -0
- data/.travis.yml +9 -19
- data/CHANGES.md +94 -42
- data/Gemfile +11 -3
- data/Guardfile +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +43 -136
- data/Rakefile +2 -0
- data/examples/echo_server.rb +1 -0
- data/ext/libev/Changes +9 -13
- data/ext/libev/ev.c +100 -74
- data/ext/libev/ev.h +4 -9
- data/ext/libev/ev_epoll.c +6 -3
- data/ext/libev/ev_kqueue.c +8 -4
- data/ext/libev/ev_poll.c +6 -3
- data/ext/libev/ev_port.c +8 -4
- data/ext/libev/ev_select.c +4 -2
- data/ext/nio4r/bytebuffer.c +265 -257
- data/ext/nio4r/extconf.rb +3 -9
- data/ext/nio4r/monitor.c +93 -46
- data/ext/nio4r/nio4r.h +6 -16
- data/ext/nio4r/org/nio4r/ByteBuffer.java +193 -209
- data/ext/nio4r/org/nio4r/Monitor.java +164 -0
- data/ext/nio4r/org/nio4r/Nio4r.java +13 -391
- data/ext/nio4r/org/nio4r/Selector.java +278 -0
- data/ext/nio4r/selector.c +72 -64
- data/lib/nio.rb +3 -3
- data/lib/nio/bytebuffer.rb +179 -132
- data/lib/nio/monitor.rb +64 -4
- data/lib/nio/selector.rb +36 -13
- data/lib/nio/version.rb +1 -1
- data/nio4r.gemspec +25 -19
- data/spec/nio/acceptables_spec.rb +6 -4
- data/spec/nio/bytebuffer_spec.rb +323 -51
- data/spec/nio/monitor_spec.rb +122 -79
- data/spec/nio/selectables/pipe_spec.rb +5 -1
- data/spec/nio/selectables/ssl_socket_spec.rb +15 -12
- data/spec/nio/selectables/tcp_socket_spec.rb +42 -31
- data/spec/nio/selectables/udp_socket_spec.rb +2 -0
- data/spec/nio/selector_spec.rb +10 -4
- data/spec/spec_helper.rb +24 -3
- data/spec/support/selectable_examples.rb +7 -5
- data/tasks/extension.rake +2 -0
- data/tasks/rspec.rake +2 -0
- data/tasks/rubocop.rake +2 -0
- metadata +18 -15
- data/.rubocop_todo.yml +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac3e49179816af644f609a1e3bbe64597ff616b8
|
4
|
+
data.tar.gz: 068bb05b019c601258e4ad8716107f0ac7cc6bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4d9dff97f7570e07e790f93ead41e84d5db0ac1c8eb9be6c7563d3833a1f12f14bae7a4dbd3e06a9c8fe91a0a79bd63a0c51f08a833d733424cf7020cc0130
|
7
|
+
data.tar.gz: 5d16069650825220774e8f7dd970364ed2b80270b8b0f28d58b8e8a05da77e1aad78c62d75945da0f5dabdb8e1aa7ce64289656e93022a88300178b5b72f486e
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,61 +1,54 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
|
1
4
|
#
|
2
|
-
#
|
5
|
+
# Lint
|
3
6
|
#
|
4
7
|
|
5
|
-
|
6
|
-
|
8
|
+
Lint/HandleExceptions:
|
9
|
+
Enabled: false
|
7
10
|
|
8
|
-
|
9
|
-
|
11
|
+
Lint/Loop:
|
12
|
+
Enabled: false
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
#
|
15
|
+
# Metrics
|
16
|
+
#
|
14
17
|
|
15
18
|
Metrics/AbcSize:
|
16
|
-
Max:
|
19
|
+
Max: 35
|
17
20
|
|
18
|
-
Metrics/
|
19
|
-
Max:
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 128
|
20
23
|
|
21
|
-
Metrics/
|
22
|
-
Max:
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 128
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
Metrics/MethodLength:
|
28
|
+
CountComments: false
|
29
|
+
Max: 50
|
26
30
|
|
27
|
-
|
28
|
-
|
31
|
+
Metrics/CyclomaticComplexity:
|
32
|
+
Max: 15
|
33
|
+
|
34
|
+
Metrics/PerceivedComplexity:
|
35
|
+
Max: 15
|
29
36
|
|
30
37
|
#
|
31
|
-
#
|
38
|
+
# Style
|
32
39
|
#
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
# Offense count: 3
|
39
|
-
Lint/Loop:
|
40
|
-
Enabled: false
|
41
|
+
Style/StringLiterals:
|
42
|
+
EnforcedStyle: double_quotes
|
41
43
|
|
42
|
-
|
43
|
-
Lint/NonLocalExitFromIterator:
|
44
|
+
Style/GlobalVars:
|
44
45
|
Enabled: false
|
45
46
|
|
46
|
-
|
47
|
-
Lint/UselessAssignment:
|
47
|
+
Style/NumericPredicate:
|
48
48
|
Enabled: false
|
49
49
|
|
50
|
-
|
51
|
-
# Configuration parameters: SupportedStyles, IndentOneStep.
|
52
|
-
Style/CaseIndentation:
|
53
|
-
IndentWhenRelativeTo: end
|
54
|
-
|
55
|
-
# Offense count: 1
|
56
|
-
Style/Documentation:
|
50
|
+
Style/RescueModifier:
|
57
51
|
Enabled: false
|
58
52
|
|
59
|
-
|
60
|
-
Style/RescueModifier:
|
53
|
+
Style/TrivialAccessors:
|
61
54
|
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/.travis.yml
CHANGED
@@ -2,25 +2,22 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
|
5
|
+
before_install:
|
6
|
+
- gem update --system 2.6.10
|
7
|
+
- gem --version
|
8
|
+
|
5
9
|
bundler_args: --without development
|
6
10
|
|
7
11
|
branches:
|
8
12
|
only:
|
9
13
|
- master
|
10
14
|
|
11
|
-
os:
|
12
|
-
- linux
|
13
|
-
- osx
|
14
|
-
|
15
15
|
rvm:
|
16
|
-
-
|
17
|
-
- 2.
|
18
|
-
- 2.
|
19
|
-
- 2.
|
16
|
+
- jruby-9.1.10.0 # latest stable
|
17
|
+
- 2.2.7
|
18
|
+
- 2.3.4
|
19
|
+
- 2.4.1
|
20
20
|
- ruby-head
|
21
|
-
- jruby-9.1.5.0 # latest stable
|
22
|
-
- jruby-head
|
23
|
-
- rbx
|
24
21
|
|
25
22
|
env:
|
26
23
|
global:
|
@@ -30,16 +27,9 @@ env:
|
|
30
27
|
- NIO4R_PURE=true
|
31
28
|
|
32
29
|
matrix:
|
33
|
-
fast_finish: true
|
34
30
|
allow_failures:
|
35
|
-
- os: osx # TODO: make tests pass reliably on OS X
|
36
31
|
- rvm: ruby-head
|
37
|
-
|
38
|
-
- rvm: rbx
|
39
|
-
- rvm: jruby-1.7
|
40
|
-
env: NIO4R_PURE=true
|
41
|
-
- rvm: jruby-9.1
|
42
|
-
env: NIO4R_PURE=true
|
32
|
+
fast_finish: true
|
43
33
|
|
44
34
|
notifications:
|
45
35
|
irc: "irc.freenode.org#celluloid"
|
data/CHANGES.md
CHANGED
@@ -1,28 +1,75 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
## 2.1.0 (2017-05-28)
|
2
|
+
|
3
|
+
* [#130](https://github.com/socketry/nio4r/pull/130)
|
4
|
+
Add -fno-strict-aliasing flag when compiling C ext.
|
5
|
+
([@junaruga])
|
6
|
+
|
7
|
+
* [#146](https://github.com/socketry/nio4r/pull/146)
|
8
|
+
Use non-blocking select when a timeout of 0 is given.
|
9
|
+
([@tarcieri])
|
10
|
+
|
11
|
+
* [#147](https://github.com/socketry/nio4r/pull/147)
|
12
|
+
Update to libev 4.24.
|
13
|
+
([@tarcieri])
|
14
|
+
|
15
|
+
* [#148](https://github.com/socketry/nio4r/pull/148)
|
16
|
+
Switch to the libev 4 API internally.
|
17
|
+
([@tarcieri])
|
18
|
+
|
19
|
+
## 2.0.0 (2016-12-28)
|
20
|
+
|
21
|
+
* [#53](https://github.com/socketry/nio4r/pull/53)
|
22
|
+
Limit lock scope to prevent recursive locking.
|
23
|
+
([@johnnyt])
|
24
|
+
|
25
|
+
* [#95](https://github.com/socketry/nio4r/pull/95)
|
26
|
+
NIO::ByteBuffer Google Summer of Code project.
|
27
|
+
([@UpeksheJay], [@tarcieri])
|
28
|
+
|
29
|
+
* [#111](https://github.com/socketry/nio4r/pull/111)
|
30
|
+
NIO::Selector#backend introspection support.
|
31
|
+
([@tarcieri])
|
32
|
+
|
33
|
+
* [#112](https://github.com/socketry/nio4r/pull/112)
|
34
|
+
Upgrade to libev 4.23.
|
35
|
+
([@tarcieri])
|
36
|
+
|
37
|
+
* [#119](https://github.com/socketry/nio4r/pull/119)
|
38
|
+
Disambiguate wakeup vs timeout (fixes #63, #66).
|
39
|
+
([@tarcieri])
|
40
|
+
|
41
|
+
* [#124](https://github.com/socketry/nio4r/pull/124)
|
42
|
+
Monitor interests API improvements.
|
43
|
+
([@tarcieri])
|
44
|
+
|
45
|
+
* Drop Ruby 2.0 and 2.1 support, require Ruby 2.2.2+.
|
46
|
+
([@tarcieri])
|
47
|
+
|
48
|
+
## 1.2.1 (2016-01-31)
|
49
|
+
|
3
50
|
* Fix bug in the JRuby backend which cases indefinite blocking when small
|
4
51
|
timeout values are passed to the selector
|
5
52
|
|
6
|
-
1.2.0 (2015-12-22)
|
7
|
-
|
53
|
+
## 1.2.0 (2015-12-22)
|
54
|
+
|
8
55
|
* Add NIO::Monitor#interests= API for changing interests. Contributed by
|
9
56
|
Upekshe Jayasekera as a Google Summer of Code project.
|
10
57
|
* Update to libev 4.22
|
11
58
|
|
12
|
-
1.1.1 (2015-07-17)
|
13
|
-
|
59
|
+
## 1.1.1 (2015-07-17)
|
60
|
+
|
14
61
|
* Update to libev 4.20
|
15
62
|
* Fall back to io.h if unistd.h is not found
|
16
63
|
* RSpec updates
|
17
64
|
* RuboCop
|
18
65
|
|
19
|
-
1.1.0 (2015-01-10)
|
20
|
-
|
66
|
+
## 1.1.0 (2015-01-10)
|
67
|
+
|
21
68
|
* Update to libev 4.19
|
22
69
|
* Do not call ev_io_stop on monitors if the loop is already closed
|
23
70
|
|
24
|
-
1.0.1 (2014-09-01)
|
25
|
-
|
71
|
+
## 1.0.1 (2014-09-01)
|
72
|
+
|
26
73
|
* Fix C compiler warnings
|
27
74
|
* Eliminate Ruby warnings about @lock_holder
|
28
75
|
* Windows improvements
|
@@ -30,59 +77,59 @@
|
|
30
77
|
* Automatically require 'set'
|
31
78
|
* Update to RSpec 3
|
32
79
|
|
33
|
-
1.0.0 (2014-01-14)
|
34
|
-
|
80
|
+
## 1.0.0 (2014-01-14)
|
81
|
+
|
35
82
|
* Have Selector#register obtain the actual IO from a Monitor object
|
36
83
|
because Monitor#initialize might convert it.
|
37
84
|
* Drop 1.8 support
|
38
85
|
|
39
|
-
0.5.0 (2013-08-06)
|
40
|
-
|
86
|
+
## 0.5.0 (2013-08-06)
|
87
|
+
|
41
88
|
* Fix segv when attempting to register to a closed selector
|
42
89
|
* Fix Windows support on Ruby 2.0.0
|
43
90
|
* Upgrade to libev 4.15
|
44
91
|
|
45
|
-
0.4.6 (2013-05-27)
|
46
|
-
|
92
|
+
## 0.4.6 (2013-05-27)
|
93
|
+
|
47
94
|
* Fix for JRuby on Windows
|
48
95
|
|
49
|
-
0.4.5
|
50
|
-
|
96
|
+
## 0.4.5
|
97
|
+
|
51
98
|
* Fix botched gem release
|
52
99
|
|
53
|
-
0.4.4
|
54
|
-
|
100
|
+
## 0.4.4
|
101
|
+
|
55
102
|
* Fix return values for Selector_synchronize and Selector_unlock
|
56
103
|
|
57
|
-
0.4.3
|
58
|
-
|
104
|
+
## 0.4.3
|
105
|
+
|
59
106
|
* REALLY have thread synchronization when closing selectors ;)
|
60
107
|
|
61
|
-
0.4.2
|
62
|
-
|
108
|
+
## 0.4.2
|
109
|
+
|
63
110
|
* Attempt to work around packaging problems with bundler-api o_O
|
64
111
|
|
65
|
-
0.4.1
|
66
|
-
|
112
|
+
## 0.4.1
|
113
|
+
|
67
114
|
* Thread synchronization when closing selectors
|
68
115
|
|
69
|
-
0.4.0
|
70
|
-
|
116
|
+
## 0.4.0
|
117
|
+
|
71
118
|
* OpenSSL::SSL::SSLSocket support
|
72
119
|
|
73
|
-
0.3.3
|
74
|
-
|
120
|
+
## 0.3.3
|
121
|
+
|
75
122
|
* NIO::Selector#select_each removed
|
76
123
|
* Remove event buffer
|
77
124
|
* Patch GIL unlock directly into libev
|
78
125
|
* Re-release since 0.3.2 was botched :(
|
79
126
|
|
80
|
-
0.3.1
|
81
|
-
|
127
|
+
## 0.3.1
|
128
|
+
|
82
129
|
* Prevent CancelledKeyExceptions on JRuby
|
83
130
|
|
84
|
-
0.3.0
|
85
|
-
|
131
|
+
## 0.3.0
|
132
|
+
|
86
133
|
* NIO::Selector#select now takes a block and behaves like select_each
|
87
134
|
* NIO::Selector#select_each is now deprecated and will be removed
|
88
135
|
* Closing monitors detaches them from their selector
|
@@ -91,23 +138,28 @@
|
|
91
138
|
* Bugfixes for zero/negative select timeouts
|
92
139
|
* Handle OP_CONNECT properly on JRuby
|
93
140
|
|
94
|
-
0.2.2
|
95
|
-
|
141
|
+
## 0.2.2
|
142
|
+
|
96
143
|
* Raise IOError if asked to wake up a closed selector
|
97
144
|
|
98
|
-
0.2.1
|
99
|
-
|
145
|
+
## 0.2.1
|
146
|
+
|
100
147
|
* Implement wakeup mechanism using raw pipes instead of ev_async, since
|
101
148
|
ev_async likes to cause segvs when used across threads (despite claims
|
102
149
|
in the documentation to the contrary)
|
103
150
|
|
104
|
-
0.2.0
|
105
|
-
|
151
|
+
## 0.2.0
|
152
|
+
|
106
153
|
* NIO::Monitor#readiness API to query readiness, along with #readable? and
|
107
154
|
#writable? helper methods
|
108
155
|
* NIO::Selector#select_each API which avoids memory allocations if possible
|
109
156
|
* Bugfixes for the JRuby implementation
|
110
157
|
|
111
|
-
0.1.0
|
112
|
-
|
158
|
+
## 0.1.0
|
159
|
+
|
113
160
|
* Initial release. Merry Christmas!
|
161
|
+
|
162
|
+
[@tarcieri]: https://github.com/tarcieri
|
163
|
+
[@johnnyt]: https://github.com/johnnyt
|
164
|
+
[@UpeksheJay]: https://github.com/UpeksheJay
|
165
|
+
[@junaruga]: https://github.com/junaruga
|
data/Gemfile
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
7
|
gem "jruby-openssl" if defined? JRUBY_VERSION
|
6
8
|
|
9
|
+
group :development do
|
10
|
+
gem "guard-rspec", require: false
|
11
|
+
gem "pry", require: false
|
12
|
+
end
|
13
|
+
|
7
14
|
group :development, :test do
|
8
|
-
gem "rake-compiler"
|
9
|
-
gem "rspec", "~> 3", require: false
|
10
|
-
gem "rubocop", "0.36.0", require: false
|
11
15
|
gem "coveralls", require: false
|
16
|
+
gem "rake-compiler", require: false
|
17
|
+
gem "rspec", "~> 3", require: false
|
18
|
+
gem "rspec-retry", require: false
|
19
|
+
gem "rubocop", "0.46.0", require: false
|
12
20
|
end
|
data/Guardfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
# 
|
2
2
|
|
3
3
|
[](http://rubygems.org/gems/nio4r)
|
4
|
-
[](https://github.com/
|
4
|
+
[](http://travis-ci.org/socketry/nio4r)
|
5
|
+
[](https://codeclimate.com/github/socketry/nio4r)
|
6
|
+
[](https://coveralls.io/r/socketry/nio4r)
|
7
|
+
[](https://github.com/socketry/nio4r/blob/master/LICENSE.txt)
|
8
8
|
|
9
|
-
_NOTE: This is the 2.x **
|
10
|
-
|
9
|
+
_NOTE: This is the 2.x **stable** branch of nio4r. For the 1.x **legacy** branch,
|
10
|
+
please see:_
|
11
11
|
|
12
|
-
https://github.com/
|
12
|
+
https://github.com/socketry/nio4r/tree/1-x-stable
|
13
13
|
|
14
14
|
**New I/O for Ruby (nio4r)**: cross-platform asynchronous I/O primitives for
|
15
15
|
scalable network clients and servers. Modeled after the Java NIO API, but
|
@@ -20,15 +20,15 @@ I/O selectors are the heart of "reactor"-based event loops, and monitor
|
|
20
20
|
multiple I/O objects for various types of readiness, e.g. ready for reading or
|
21
21
|
writing.
|
22
22
|
|
23
|
-
[Rails 5]: https://rubygems.org/gems/actioncable
|
24
|
-
|
25
23
|
## Projects using nio4r
|
26
24
|
|
27
25
|
* [ActionCable]: Rails 5 WebSocket protocol, uses nio4r for a WebSocket server
|
28
26
|
* [Celluloid::IO]: Actor-based concurrency framework, uses nio4r for async I/O
|
27
|
+
* [Socketry Async]: Asynchronous I/O framework for Ruby
|
29
28
|
|
30
29
|
[ActionCable]: https://rubygems.org/gems/actioncable
|
31
30
|
[Celluloid::IO]: https://github.com/celluloid/celluloid-io
|
31
|
+
[Socketry Async]: https://github.com/socketry/async
|
32
32
|
|
33
33
|
## Goals
|
34
34
|
|
@@ -39,142 +39,46 @@ writing.
|
|
39
39
|
|
40
40
|
## Supported platforms
|
41
41
|
|
42
|
-
* Ruby 2.
|
43
|
-
* Ruby 2.1
|
44
|
-
* Ruby 2.2
|
42
|
+
* Ruby 2.2.2+
|
45
43
|
* Ruby 2.3
|
44
|
+
* Ruby 2.4
|
46
45
|
* JRuby 9000
|
47
|
-
* Pure Ruby using Kernel.select
|
48
|
-
|
49
|
-
## Platform notes
|
50
|
-
|
51
|
-
* MRI/YARV and Rubinius implement nio4r with a C extension based on libev,
|
52
|
-
which provides a high performance binding to native IO APIs
|
53
|
-
* JRuby uses a Java extension based on the high performance Java NIO subsystem
|
54
|
-
* A pure Ruby implementation is also provided for Ruby implementations which
|
55
|
-
don't implement the MRI C extension API
|
56
|
-
|
57
|
-
## Usage
|
58
|
-
|
59
|
-
If you're interested in using nio4r for a project but just getting started,
|
60
|
-
check out this blog post which provides some background and examples:
|
61
|
-
|
62
|
-
[A gentle introduction to nio4r: low-level portable asynchronous I/O for Ruby][blogpost]
|
63
|
-
|
64
|
-
[blogpost]: https://tonyarcieri.com/a-gentle-introduction-to-nio4r
|
65
|
-
|
66
|
-
### Selectors
|
67
|
-
|
68
|
-
The NIO::Selector class is the main API provided by nio4r. Use it where you
|
69
|
-
might otherwise use Kernel.select, but want to monitor the same set of IO
|
70
|
-
objects across multiple select calls rather than having to reregister them
|
71
|
-
every single time:
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
require 'nio'
|
75
46
|
|
76
|
-
|
77
|
-
```
|
47
|
+
## Supported backends
|
78
48
|
|
79
|
-
|
80
|
-
|
81
|
-
|
49
|
+
* **libev**: MRI C extension targeting multiple native IO selector APIs (e.g epoll, kqueue)
|
50
|
+
* **Java NIO**: JRuby extension which wraps the Java NIO subsystem
|
51
|
+
* **Pure Ruby**: `Kernel.select`-based backend that should work on any Ruby interpreter
|
82
52
|
|
83
|
-
|
84
|
-
>> reader, writer = IO.pipe
|
85
|
-
=> [#<IO:0xf30>, #<IO:0xf34>]
|
86
|
-
>> monitor = selector.register(reader, :r)
|
87
|
-
=> #<NIO::Monitor:0xfbc>
|
88
|
-
```
|
53
|
+
## Discussion
|
89
54
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
provides an easy way to implement callbacks:
|
55
|
+
For discussion and general help with nio4r, email
|
56
|
+
[socketry+subscribe@googlegroups.com][subscribe]
|
57
|
+
or join on the web via the [Google Group].
|
94
58
|
|
95
|
-
|
96
|
-
>> monitor = selector.register(reader, :r)
|
97
|
-
=> #<NIO::Monitor:0xfbc>
|
98
|
-
>> monitor.value = proc { puts "Got some data: #{monitor.io.read_nonblock(4096)}" }
|
99
|
-
=> #<Proc:0x1000@(irb):4>
|
100
|
-
```
|
59
|
+
We're also on IRC at ##socketry on irc.freenode.net.
|
101
60
|
|
102
|
-
|
103
|
-
|
61
|
+
[subscribe]: mailto:socketry+subscribe@googlegroups.com
|
62
|
+
[google group]: https://groups.google.com/group/socketry
|
104
63
|
|
105
|
-
|
106
|
-
>> writer << "Hi there!"
|
107
|
-
=> #<IO:0x103c>
|
108
|
-
>> ready = selector.select
|
109
|
-
=> [#<NIO::Monitor:0xfbc>]
|
110
|
-
>> ready.each { |m| m.value.call }
|
111
|
-
Got some data: Hi there!
|
112
|
-
=> [#<NIO::Monitor:0xfbc>]
|
113
|
-
```
|
64
|
+
## Documentation
|
114
65
|
|
115
|
-
|
116
|
-
|
117
|
-
wait in seconds to NIO::Selector#select just like you can with Kernel.select:
|
66
|
+
[Please see the nio4r wiki](https://github.com/socketry/nio4r/wiki)
|
67
|
+
for more detailed documentation and usage notes:
|
118
68
|
|
119
|
-
|
120
|
-
|
121
|
-
|
69
|
+
* [Getting Started]: Introduction to nio4r's components
|
70
|
+
* [Selectors]: monitor multiple `IO` objects for readiness events
|
71
|
+
* [Monitors]: control interests and inspect readiness for specific `IO` objects
|
72
|
+
* [Byte Buffers]: fixed-size native buffers for high-performance I/O
|
122
73
|
|
123
|
-
|
74
|
+
[Getting Started]: https://github.com/socketry/nio4r/wiki/Getting-Started
|
75
|
+
[Selectors]: https://github.com/socketry/nio4r/wiki/Selectors
|
76
|
+
[Monitors]: https://github.com/socketry/nio4r/wiki/Monitors
|
77
|
+
[Byte Buffers]: https://github.com/socketry/nio4r/wiki/Byte-Buffers
|
124
78
|
|
125
|
-
|
126
|
-
passing a block to select. The block will be called for each ready monitor
|
127
|
-
object, with that object passed as an argument. The number of ready monitors
|
128
|
-
is returned as a Fixnum:
|
79
|
+
See also:
|
129
80
|
|
130
|
-
|
131
|
-
>> selector.select { |m| m.value.call }
|
132
|
-
Got some data: Hi there!
|
133
|
-
=> 1
|
134
|
-
```
|
135
|
-
|
136
|
-
When you're done monitoring a particular IO object, just deregister it from
|
137
|
-
the selector:
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
selector.deregister(reader)
|
141
|
-
```
|
142
|
-
|
143
|
-
### Monitors
|
144
|
-
|
145
|
-
Monitors provide methods which let you introspect on why a particular IO
|
146
|
-
object was selected. These methods are not thread safe unless you are holding
|
147
|
-
the selector lock (i.e. if you're in a block passed to #select). Only use them
|
148
|
-
if you aren't concerned with thread safety, or you're within a #select
|
149
|
-
block:
|
150
|
-
|
151
|
-
- ***#interests***: what this monitor is interested in (:r, :w, or :rw)
|
152
|
-
- ***#interests=***: change the current interests for a monitor (to :r, :w, or :rw)
|
153
|
-
- ***#readiness***: what I/O operations the monitored object is ready for
|
154
|
-
- ***#readable?***: was the IO readable last time it was selected?
|
155
|
-
- ***#writable?***: was the IO writable last time it was selected?
|
156
|
-
|
157
|
-
Monitors also support a ***#value*** and ***#value=*** method for storing a
|
158
|
-
handle to an arbitrary object of your choice (e.g. a proc)
|
159
|
-
|
160
|
-
### Flow Control
|
161
|
-
|
162
|
-
For information on how to compose nio4r selectors inside of event loops,
|
163
|
-
please read the [Flow Control Guide on the
|
164
|
-
Wiki](https://github.com/celluloid/nio4r/wiki/Basic-Flow-Control)
|
165
|
-
|
166
|
-
## Concurrency
|
167
|
-
|
168
|
-
**nio4r** provides internal locking to ensure that it's safe to use from multiple
|
169
|
-
concurrent threads. Only one thread can select on a NIO::Selector at a given
|
170
|
-
time, and while a thread is selecting other threads are blocked from
|
171
|
-
registering or deregistering IO objects. Once a pending select has completed,
|
172
|
-
requests to register/unregister IO objects will be processed.
|
173
|
-
|
174
|
-
NIO::Selector#wakeup allows one thread to unblock another thread that's in the
|
175
|
-
middle of an NIO::Selector#select operation. This lets other threads that need
|
176
|
-
to communicate immediately with the selector unblock it so it can process
|
177
|
-
other events that it's not presently selecting on.
|
81
|
+
* [YARD API documentation](http://www.rubydoc.info/gems/nio4r/frames)
|
178
82
|
|
179
83
|
## Non-goals
|
180
84
|
|
@@ -189,8 +93,11 @@ to maintain a large codebase.
|
|
189
93
|
|
190
94
|
## License
|
191
95
|
|
192
|
-
Copyright (c) 2011-
|
193
|
-
See LICENSE.txt for further details.
|
96
|
+
Copyright (c) 2011-2017 Tony Arcieri. Distributed under the MIT License.
|
97
|
+
See [LICENSE.txt] for further details.
|
98
|
+
|
99
|
+
Includes libev 4.24. Copyright (c) 2007-2016 Marc Alexander Lehmann.
|
100
|
+
Distributed under the BSD license. See [ext/libev/LICENSE] for details.
|
194
101
|
|
195
|
-
|
196
|
-
|
102
|
+
[LICENSE.txt]: https://github.com/socketry/nio4r/blob/master/LICENSE.txt
|
103
|
+
[ext/libev/LICENSE]: https://github.com/socketry/nio4r/blob/master/ext/libev/LICENSE
|