nio4r 2.0.0.pre → 2.0.0
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 +4 -21
- data/CHANGES.md +75 -42
- data/Gemfile +11 -3
- data/Guardfile +10 -0
- data/LICENSE.txt +1 -1
- data/README.md +32 -136
- data/Rakefile +2 -0
- data/examples/echo_server.rb +1 -0
- data/ext/libev/Changes +4 -13
- data/ext/libev/ev.c +100 -74
- data/ext/libev/ev.h +3 -3
- 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 +2 -10
- data/ext/nio4r/monitor.c +93 -46
- data/ext/nio4r/nio4r.h +5 -15
- 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 +52 -52
- 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 +15 -11
- 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: 9f553c279692e1cf308af13c716610b424caca04
|
4
|
+
data.tar.gz: 7cd52022633fd0a5d2ba26f003e976505a783237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bdc6f608f34b8be39efa968e523f9bac24da9dc976467afb7ff2d271ca234b6c46d614f37f2c5b82bcbab56c11b3835d0c2c5c26028b794b1dd26ffdee86b83
|
7
|
+
data.tar.gz: 32a6b982cbd25605a031d39b7fdb9208b767be7d11f842405fd081f384addb372e1e1fec846176e78f5a77c81e8a21bdf5709eb76753fd85b43583b819e75d5d
|
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
@@ -8,19 +8,11 @@ branches:
|
|
8
8
|
only:
|
9
9
|
- master
|
10
10
|
|
11
|
-
os:
|
12
|
-
- linux
|
13
|
-
- osx
|
14
|
-
|
15
11
|
rvm:
|
16
|
-
-
|
17
|
-
- 2.
|
18
|
-
- 2.
|
19
|
-
- 2.
|
20
|
-
- ruby-head
|
21
|
-
- jruby-9.1.5.0 # latest stable
|
22
|
-
- jruby-head
|
23
|
-
- rbx
|
12
|
+
- jruby-9.1.6.0 # latest stable
|
13
|
+
- 2.2.2
|
14
|
+
- 2.3.3
|
15
|
+
- 2.4.0
|
24
16
|
|
25
17
|
env:
|
26
18
|
global:
|
@@ -31,15 +23,6 @@ env:
|
|
31
23
|
|
32
24
|
matrix:
|
33
25
|
fast_finish: true
|
34
|
-
allow_failures:
|
35
|
-
- os: osx # TODO: make tests pass reliably on OS X
|
36
|
-
- rvm: ruby-head
|
37
|
-
- rvm: jruby-head
|
38
|
-
- rvm: rbx
|
39
|
-
- rvm: jruby-1.7
|
40
|
-
env: NIO4R_PURE=true
|
41
|
-
- rvm: jruby-9.1
|
42
|
-
env: NIO4R_PURE=true
|
43
26
|
|
44
27
|
notifications:
|
45
28
|
irc: "irc.freenode.org#celluloid"
|
data/CHANGES.md
CHANGED
@@ -1,28 +1,57 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
## 2.0.0 (2016-12-28)
|
2
|
+
|
3
|
+
* [#53](https://github.com/socketry/nio4r/pull/53)
|
4
|
+
Limit lock scope to prevent recursive locking.
|
5
|
+
([@johnnyt])
|
6
|
+
|
7
|
+
* [#95](https://github.com/socketry/nio4r/pull/95)
|
8
|
+
NIO::ByteBuffer Google Summer of Code project.
|
9
|
+
([@UpeksheJay], [@tarcieri])
|
10
|
+
|
11
|
+
* [#111](https://github.com/socketry/nio4r/pull/111)
|
12
|
+
NIO::Selector#backend introspection support.
|
13
|
+
([@tarcieri])
|
14
|
+
|
15
|
+
* [#112](https://github.com/socketry/nio4r/pull/112)
|
16
|
+
Upgrade to libev 4.23.
|
17
|
+
([@tarcieri])
|
18
|
+
|
19
|
+
* [#119](https://github.com/socketry/nio4r/pull/119)
|
20
|
+
Disambiguate wakeup vs timeout (fixes #63, #66).
|
21
|
+
([@tarcieri])
|
22
|
+
|
23
|
+
* [#124](https://github.com/socketry/nio4r/pull/124)
|
24
|
+
Monitor interests API improvements.
|
25
|
+
([@tarcieri])
|
26
|
+
|
27
|
+
* Drop Ruby 2.0 and 2.1 support, require Ruby 2.2.2+.
|
28
|
+
([@tarcieri])
|
29
|
+
|
30
|
+
## 1.2.1 (2016-01-31)
|
31
|
+
|
3
32
|
* Fix bug in the JRuby backend which cases indefinite blocking when small
|
4
33
|
timeout values are passed to the selector
|
5
34
|
|
6
|
-
1.2.0 (2015-12-22)
|
7
|
-
|
35
|
+
## 1.2.0 (2015-12-22)
|
36
|
+
|
8
37
|
* Add NIO::Monitor#interests= API for changing interests. Contributed by
|
9
38
|
Upekshe Jayasekera as a Google Summer of Code project.
|
10
39
|
* Update to libev 4.22
|
11
40
|
|
12
|
-
1.1.1 (2015-07-17)
|
13
|
-
|
41
|
+
## 1.1.1 (2015-07-17)
|
42
|
+
|
14
43
|
* Update to libev 4.20
|
15
44
|
* Fall back to io.h if unistd.h is not found
|
16
45
|
* RSpec updates
|
17
46
|
* RuboCop
|
18
47
|
|
19
|
-
1.1.0 (2015-01-10)
|
20
|
-
|
48
|
+
## 1.1.0 (2015-01-10)
|
49
|
+
|
21
50
|
* Update to libev 4.19
|
22
51
|
* Do not call ev_io_stop on monitors if the loop is already closed
|
23
52
|
|
24
|
-
1.0.1 (2014-09-01)
|
25
|
-
|
53
|
+
## 1.0.1 (2014-09-01)
|
54
|
+
|
26
55
|
* Fix C compiler warnings
|
27
56
|
* Eliminate Ruby warnings about @lock_holder
|
28
57
|
* Windows improvements
|
@@ -30,59 +59,59 @@
|
|
30
59
|
* Automatically require 'set'
|
31
60
|
* Update to RSpec 3
|
32
61
|
|
33
|
-
1.0.0 (2014-01-14)
|
34
|
-
|
62
|
+
## 1.0.0 (2014-01-14)
|
63
|
+
|
35
64
|
* Have Selector#register obtain the actual IO from a Monitor object
|
36
65
|
because Monitor#initialize might convert it.
|
37
66
|
* Drop 1.8 support
|
38
67
|
|
39
|
-
0.5.0 (2013-08-06)
|
40
|
-
|
68
|
+
## 0.5.0 (2013-08-06)
|
69
|
+
|
41
70
|
* Fix segv when attempting to register to a closed selector
|
42
71
|
* Fix Windows support on Ruby 2.0.0
|
43
72
|
* Upgrade to libev 4.15
|
44
73
|
|
45
|
-
0.4.6 (2013-05-27)
|
46
|
-
|
74
|
+
## 0.4.6 (2013-05-27)
|
75
|
+
|
47
76
|
* Fix for JRuby on Windows
|
48
77
|
|
49
|
-
0.4.5
|
50
|
-
|
78
|
+
## 0.4.5
|
79
|
+
|
51
80
|
* Fix botched gem release
|
52
81
|
|
53
|
-
0.4.4
|
54
|
-
|
82
|
+
## 0.4.4
|
83
|
+
|
55
84
|
* Fix return values for Selector_synchronize and Selector_unlock
|
56
85
|
|
57
|
-
0.4.3
|
58
|
-
|
86
|
+
## 0.4.3
|
87
|
+
|
59
88
|
* REALLY have thread synchronization when closing selectors ;)
|
60
89
|
|
61
|
-
0.4.2
|
62
|
-
|
90
|
+
## 0.4.2
|
91
|
+
|
63
92
|
* Attempt to work around packaging problems with bundler-api o_O
|
64
93
|
|
65
|
-
0.4.1
|
66
|
-
|
94
|
+
## 0.4.1
|
95
|
+
|
67
96
|
* Thread synchronization when closing selectors
|
68
97
|
|
69
|
-
0.4.0
|
70
|
-
|
98
|
+
## 0.4.0
|
99
|
+
|
71
100
|
* OpenSSL::SSL::SSLSocket support
|
72
101
|
|
73
|
-
0.3.3
|
74
|
-
|
102
|
+
## 0.3.3
|
103
|
+
|
75
104
|
* NIO::Selector#select_each removed
|
76
105
|
* Remove event buffer
|
77
106
|
* Patch GIL unlock directly into libev
|
78
107
|
* Re-release since 0.3.2 was botched :(
|
79
108
|
|
80
|
-
0.3.1
|
81
|
-
|
109
|
+
## 0.3.1
|
110
|
+
|
82
111
|
* Prevent CancelledKeyExceptions on JRuby
|
83
112
|
|
84
|
-
0.3.0
|
85
|
-
|
113
|
+
## 0.3.0
|
114
|
+
|
86
115
|
* NIO::Selector#select now takes a block and behaves like select_each
|
87
116
|
* NIO::Selector#select_each is now deprecated and will be removed
|
88
117
|
* Closing monitors detaches them from their selector
|
@@ -91,23 +120,27 @@
|
|
91
120
|
* Bugfixes for zero/negative select timeouts
|
92
121
|
* Handle OP_CONNECT properly on JRuby
|
93
122
|
|
94
|
-
0.2.2
|
95
|
-
|
123
|
+
## 0.2.2
|
124
|
+
|
96
125
|
* Raise IOError if asked to wake up a closed selector
|
97
126
|
|
98
|
-
0.2.1
|
99
|
-
|
127
|
+
## 0.2.1
|
128
|
+
|
100
129
|
* Implement wakeup mechanism using raw pipes instead of ev_async, since
|
101
130
|
ev_async likes to cause segvs when used across threads (despite claims
|
102
131
|
in the documentation to the contrary)
|
103
132
|
|
104
|
-
0.2.0
|
105
|
-
|
133
|
+
## 0.2.0
|
134
|
+
|
106
135
|
* NIO::Monitor#readiness API to query readiness, along with #readable? and
|
107
136
|
#writable? helper methods
|
108
137
|
* NIO::Selector#select_each API which avoids memory allocations if possible
|
109
138
|
* Bugfixes for the JRuby implementation
|
110
139
|
|
111
|
-
0.1.0
|
112
|
-
|
140
|
+
## 0.1.0
|
141
|
+
|
113
142
|
* Initial release. Merry Christmas!
|
143
|
+
|
144
|
+
[@tarcieri]: https://github.com/tarcieri
|
145
|
+
[@johnnyt]: https://github.com/johnnyt
|
146
|
+
[@UpeksheJay]: https://github.com/UpeksheJay
|
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
9
|
_NOTE: This is the 2.x **development** branch of nio4r. For the 1.x **stable**
|
10
10
|
branch (used by [Rails 5]), 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
|
@@ -28,7 +28,7 @@ writing.
|
|
28
28
|
* [Celluloid::IO]: Actor-based concurrency framework, uses nio4r for async I/O
|
29
29
|
|
30
30
|
[ActionCable]: https://rubygems.org/gems/actioncable
|
31
|
-
[Celluloid::IO]: https://github.com/
|
31
|
+
[Celluloid::IO]: https://github.com/socketry/socketry-io
|
32
32
|
|
33
33
|
## Goals
|
34
34
|
|
@@ -39,142 +39,35 @@ 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
46
|
|
49
|
-
##
|
47
|
+
## Supported backends
|
50
48
|
|
51
|
-
* MRI
|
52
|
-
|
53
|
-
*
|
54
|
-
* A pure Ruby implementation is also provided for Ruby implementations which
|
55
|
-
don't implement the MRI C extension API
|
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
|
56
52
|
|
57
|
-
##
|
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:
|
53
|
+
## Documentation
|
61
54
|
|
62
|
-
[
|
55
|
+
[Please see the nio4r wiki](https://github.com/socketry/nio4r/wiki)
|
56
|
+
for more detailed documentation and usage notes:
|
63
57
|
|
64
|
-
[
|
58
|
+
* [Getting Started]: Introduction to nio4r's components
|
59
|
+
* [Selectors]: monitor multiple `IO` objects for readiness events
|
60
|
+
* [Monitors]: control interests and inspect readiness for specific `IO` objects
|
61
|
+
* [Byte Buffers]: fixed-size native buffers for high-performance I/O
|
65
62
|
|
66
|
-
|
63
|
+
[Getting Started]: https://github.com/socketry/nio4r/wiki/Getting-Started
|
64
|
+
[Selectors]: https://github.com/socketry/nio4r/wiki/Selectors
|
65
|
+
[Monitors]: https://github.com/socketry/nio4r/wiki/Monitors
|
66
|
+
[Byte Buffers]: https://github.com/socketry/nio4r/wiki/Byte-Buffers
|
67
67
|
|
68
|
-
|
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:
|
68
|
+
See also:
|
72
69
|
|
73
|
-
|
74
|
-
require 'nio'
|
75
|
-
|
76
|
-
selector = NIO::Selector.new
|
77
|
-
```
|
78
|
-
|
79
|
-
To monitor IO objects, attach them to the selector with the NIO::Selector#register
|
80
|
-
method, monitoring them for read readiness with the :r parameter, write
|
81
|
-
readiness with the :w parameter, or both with :rw.
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
>> reader, writer = IO.pipe
|
85
|
-
=> [#<IO:0xf30>, #<IO:0xf34>]
|
86
|
-
>> monitor = selector.register(reader, :r)
|
87
|
-
=> #<NIO::Monitor:0xfbc>
|
88
|
-
```
|
89
|
-
|
90
|
-
After registering an IO object with the selector, you'll get a NIO::Monitor
|
91
|
-
object which you can use for managing how a particular IO object is being
|
92
|
-
monitored. Monitors will store an arbitrary value of your choice, which
|
93
|
-
provides an easy way to implement callbacks:
|
94
|
-
|
95
|
-
```ruby
|
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
|
-
```
|
101
|
-
|
102
|
-
The main method of importance is NIO::Selector#select, which monitors all
|
103
|
-
registered IO objects and returns an array of monitors that are ready.
|
104
|
-
|
105
|
-
```ruby
|
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
|
-
```
|
114
|
-
|
115
|
-
By default, NIO::Selector#select will block indefinitely until one of the IO
|
116
|
-
objects being monitored becomes ready. However, you can also pass a timeout to
|
117
|
-
wait in seconds to NIO::Selector#select just like you can with Kernel.select:
|
118
|
-
|
119
|
-
```ruby
|
120
|
-
ready = selector.select(15) # Wait 15 seconds
|
121
|
-
```
|
122
|
-
|
123
|
-
If a timeout occurs, ready will be nil.
|
124
|
-
|
125
|
-
You can avoid allocating an array each time you call NIO::Selector#select by
|
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:
|
129
|
-
|
130
|
-
```ruby
|
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.
|
70
|
+
* [YARD API documentation](http://www.rubydoc.info/gems/nio4r/frames)
|
178
71
|
|
179
72
|
## Non-goals
|
180
73
|
|
@@ -190,7 +83,10 @@ to maintain a large codebase.
|
|
190
83
|
## License
|
191
84
|
|
192
85
|
Copyright (c) 2011-2016 Tony Arcieri. Distributed under the MIT License.
|
193
|
-
See LICENSE.txt for further details.
|
86
|
+
See [LICENSE.txt] for further details.
|
87
|
+
|
88
|
+
Includes libev 4.23. Copyright (c) 2007-2016 Marc Alexander Lehmann.
|
89
|
+
Distributed under the BSD license. See [ext/libev/LICENSE] for details.
|
194
90
|
|
195
|
-
|
196
|
-
|
91
|
+
[LICENSE.txt]: https://github.com/socketry/nio4r/blob/master/LICENSE.txt
|
92
|
+
[ext/libev/LICENSE]: https://github.com/socketry/nio4r/blob/master/ext/libev/LICENSE
|