nio4r 1.2.1-java → 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rubocop.yml +31 -38
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +15 -14
  6. data/CHANGES.md +75 -42
  7. data/Gemfile +10 -5
  8. data/Guardfile +10 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +57 -161
  11. data/Rakefile +2 -1
  12. data/examples/echo_server.rb +1 -0
  13. data/ext/libev/Changes +4 -13
  14. data/ext/libev/ev.c +101 -74
  15. data/ext/libev/ev.h +3 -3
  16. data/ext/libev/ev_epoll.c +6 -3
  17. data/ext/libev/ev_kqueue.c +8 -4
  18. data/ext/libev/ev_poll.c +6 -3
  19. data/ext/libev/ev_port.c +8 -4
  20. data/ext/libev/ev_select.c +4 -2
  21. data/ext/nio4r/bytebuffer.c +421 -0
  22. data/ext/nio4r/extconf.rb +2 -10
  23. data/ext/nio4r/monitor.c +93 -46
  24. data/ext/nio4r/nio4r.h +11 -13
  25. data/ext/nio4r/org/nio4r/ByteBuffer.java +295 -0
  26. data/ext/nio4r/org/nio4r/Monitor.java +164 -0
  27. data/ext/nio4r/org/nio4r/Nio4r.java +22 -391
  28. data/ext/nio4r/org/nio4r/Selector.java +278 -0
  29. data/ext/nio4r/selector.c +55 -53
  30. data/lib/nio.rb +4 -3
  31. data/lib/nio/bytebuffer.rb +222 -0
  32. data/lib/nio/monitor.rb +64 -4
  33. data/lib/nio/selector.rb +52 -20
  34. data/lib/nio/version.rb +1 -1
  35. data/nio4r.gemspec +25 -19
  36. data/spec/nio/acceptables_spec.rb +6 -4
  37. data/spec/nio/bytebuffer_spec.rb +349 -0
  38. data/spec/nio/monitor_spec.rb +122 -79
  39. data/spec/nio/selectables/pipe_spec.rb +5 -1
  40. data/spec/nio/selectables/ssl_socket_spec.rb +15 -12
  41. data/spec/nio/selectables/tcp_socket_spec.rb +42 -31
  42. data/spec/nio/selectables/udp_socket_spec.rb +2 -0
  43. data/spec/nio/selector_spec.rb +10 -4
  44. data/spec/spec_helper.rb +24 -3
  45. data/spec/support/selectable_examples.rb +7 -5
  46. data/tasks/extension.rake +2 -0
  47. data/tasks/rspec.rake +2 -0
  48. data/tasks/rubocop.rake +2 -0
  49. metadata +21 -14
  50. data/.rubocop_todo.yml +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27ed3f9e4814ea11b179f4852fec22ae987ce176
4
- data.tar.gz: 2a5c3b0c1989783fa59580869ce67c95bdb7baad
3
+ metadata.gz: 2685d0b193772fb648d55b9ce46f6ce0ebffa646
4
+ data.tar.gz: babb78d3c1e768b192b8b51062ac23eb4d94270e
5
5
  SHA512:
6
- metadata.gz: f72319ce240707fdab1bccb6d3e5fa242f064f33d781559f3cc461821fc54a584bd9a598efbd676aa1af884dad32c2704e6f0972fa5d678499284bd0078f16e4
7
- data.tar.gz: 557a30f1a8f152226e2da665c33d450f0f12031f1c25953c1219d18e8ce95fa0b427cea67359e2cf6229b3c33cf577cb31a69e750469c6b5b5bfedc9347eaa5e
6
+ metadata.gz: 71ceb314a13ec706fd72168850787bf2dd7942fe66b0cdbbf1d9b5bce4f4977a5dbcd9b4f0c04ab6f8daf3769f4a3e7daebea714c1b609df4371472082f63216
7
+ data.tar.gz: e16b5359765c62a6fcc443ea26c3bad5e7466b7e3d6c4cc93f8dc2993a872a13887bb3756d1ec6581dfc77a1a1e79798cce960042a830e2b6732c9ff2931c8b0
data/.rspec CHANGED
@@ -1,5 +1,4 @@
1
1
  --color
2
2
  --format documentation
3
- --backtrace
4
3
  --order random
5
4
  --warnings
data/.rubocop.yml CHANGED
@@ -1,61 +1,54 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
1
4
  #
2
- # Deliberate style choices
5
+ # Lint
3
6
  #
4
7
 
5
- LineLength:
6
- Max: 100
8
+ Lint/HandleExceptions:
9
+ Enabled: false
7
10
 
8
- Style/StringLiterals:
9
- EnforcedStyle: double_quotes
11
+ Lint/Loop:
12
+ Enabled: false
10
13
 
11
- Metrics/MethodLength:
12
- CountComments: false
13
- Max: 40
14
+ #
15
+ # Metrics
16
+ #
14
17
 
15
18
  Metrics/AbcSize:
16
- Max: 40
19
+ Max: 35
17
20
 
18
- Metrics/PerceivedComplexity:
19
- Max: 15
21
+ Metrics/ClassLength:
22
+ Max: 128
20
23
 
21
- Metrics/CyclomaticComplexity:
22
- Max: 10
24
+ Metrics/LineLength:
25
+ Max: 128
23
26
 
24
- Style/GlobalVars:
25
- Enabled: false
27
+ Metrics/MethodLength:
28
+ CountComments: false
29
+ Max: 50
26
30
 
27
- Style/TrivialAccessors:
28
- Enabled: false
31
+ Metrics/CyclomaticComplexity:
32
+ Max: 15
33
+
34
+ Metrics/PerceivedComplexity:
35
+ Max: 15
29
36
 
30
37
  #
31
- # Auto-generated overrides
38
+ # Style
32
39
  #
33
40
 
34
- # Offense count: 2
35
- Lint/HandleExceptions:
36
- Enabled: false
37
-
38
- # Offense count: 3
39
- Lint/Loop:
40
- Enabled: false
41
+ Style/StringLiterals:
42
+ EnforcedStyle: double_quotes
41
43
 
42
- # Offense count: 1
43
- Lint/NonLocalExitFromIterator:
44
+ Style/GlobalVars:
44
45
  Enabled: false
45
46
 
46
- # Offense count: 7
47
- Lint/UselessAssignment:
47
+ Style/NumericPredicate:
48
48
  Enabled: false
49
49
 
50
- # Offense count: 1
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
- # Offense count: 2
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
@@ -1,27 +1,28 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ cache: bundler
4
+
5
+ bundler_args: --without development
6
+
7
+ branches:
8
+ only:
9
+ - master
3
10
 
4
11
  rvm:
5
- - 2.0.0
6
- - 2.1.1
12
+ - jruby-9.1.6.0 # latest stable
7
13
  - 2.2.2
8
- - ruby-head
9
- - jruby
10
- - jruby-head
11
- - rbx-2
14
+ - 2.3.3
15
+ - 2.4.0
12
16
 
13
17
  env:
14
- - NIO4R_PURE=false
15
- - NIO4R_PURE=true
18
+ global:
19
+ - JRUBY_OPTS="--dev -J-Djruby.launch.inproc=true -J-Xmx1024M"
20
+ matrix:
21
+ - NIO4R_PURE=false
22
+ - NIO4R_PURE=true
16
23
 
17
24
  matrix:
18
25
  fast_finish: true
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-head
22
- - rvm: rbx-2
23
- - rvm: jruby
24
- env: NIO4R_PURE=true
25
26
 
26
27
  notifications:
27
28
  irc: "irc.freenode.org#celluloid"
data/CHANGES.md CHANGED
@@ -1,28 +1,57 @@
1
- 1.2.1 (2016-01-31)
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
@@ -5,11 +7,14 @@ gemspec
5
7
  gem "jruby-openssl" if defined? JRUBY_VERSION
6
8
 
7
9
  group :development do
8
- gem "rake-compiler"
10
+ gem "guard-rspec", require: false
11
+ gem "pry", require: false
9
12
  end
10
13
 
11
- group :test do
12
- gem "rspec", "~> 3.0"
13
- gem "rubocop", "0.36.0"
14
- gem "coveralls", require: false
14
+ group :development, :test do
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
15
20
  end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ directories %w(lib spec)
4
+ clearing :on
5
+
6
+ guard :rspec, cmd: "bundle exec rspec" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch("spec/spec_helper.rb") { "spec" }
10
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-12 Tony Arcieri
1
+ Copyright (c) 2011-16 Tony Arcieri
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,196 +1,92 @@
1
- ![nio4r](https://raw.github.com/celluloid/nio4r/master/logo.png)
2
- ===============
1
+ # ![nio4r](https://raw.github.com/socketry/nio4r/master/logo.png)
2
+
3
3
  [![Gem Version](https://badge.fury.io/rb/nio4r.svg)](http://rubygems.org/gems/nio4r)
4
- [![Build Status](https://secure.travis-ci.org/celluloid/nio4r.svg?branch=master)](http://travis-ci.org/celluloid/nio4r)
5
- [![Code Climate](https://codeclimate.com/github/celluloid/nio4r.svg)](https://codeclimate.com/github/celluloid/nio4r)
6
- [![Coverage Status](https://coveralls.io/repos/celluloid/nio4r/badge.svg?branch=master)](https://coveralls.io/r/celluloid/nio4r)
7
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/celluloid/nio4r/blob/master/LICENSE.txt)
4
+ [![Build Status](https://secure.travis-ci.org/socketry/nio4r.svg?branch=master)](http://travis-ci.org/socketry/nio4r)
5
+ [![Code Climate](https://codeclimate.com/github/socketry/nio4r.svg)](https://codeclimate.com/github/socketry/nio4r)
6
+ [![Coverage Status](https://coveralls.io/repos/socketry/nio4r/badge.svg?branch=master)](https://coveralls.io/r/socketry/nio4r)
7
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/socketry/nio4r/blob/master/LICENSE.txt)
8
+
9
+ _NOTE: This is the 2.x **development** branch of nio4r. For the 1.x **stable**
10
+ branch (used by [Rails 5]), please see:_
8
11
 
9
- nio4r: New IO for Ruby.
12
+ https://github.com/socketry/nio4r/tree/1-x-stable
10
13
 
11
- nio4r provides an abstract, cross-platform stateful I/O selector API for Ruby.
14
+ **New I/O for Ruby (nio4r)**: cross-platform asynchronous I/O primitives for
15
+ scalable network clients and servers. Modeled after the Java NIO API, but
16
+ simplified for ease-of-use.
17
+
18
+ **nio4r** provides an abstract, cross-platform stateful I/O selector API for Ruby.
12
19
  I/O selectors are the heart of "reactor"-based event loops, and monitor
13
20
  multiple I/O objects for various types of readiness, e.g. ready for reading or
14
21
  writing.
15
22
 
16
- The most similar API provided by Ruby today is Kernel.select, however the
17
- select API requires you to pass in arrays of all of the I/O objects you're
18
- interested in every time. nio4r provides a more object-oriented API that lets
19
- you register I/O objects with a selector then handle them when they're selected
20
- for various types of events.
23
+ [Rails 5]: https://rubygems.org/gems/actioncable
24
+
25
+ ## Projects using nio4r
21
26
 
22
- nio4r is modeled after the Java NIO API, but simplified for ease-of-use.
27
+ * [ActionCable]: Rails 5 WebSocket protocol, uses nio4r for a WebSocket server
28
+ * [Celluloid::IO]: Actor-based concurrency framework, uses nio4r for async I/O
23
29
 
24
- Its goals are:
30
+ [ActionCable]: https://rubygems.org/gems/actioncable
31
+ [Celluloid::IO]: https://github.com/socketry/socketry-io
32
+
33
+ ## Goals
25
34
 
26
35
  * Expose high-level interfaces for stateful IO selectors
27
36
  * Keep the API small to maximize both portability and performance across many
28
37
  different OSes and Ruby VMs
29
38
  * Provide inherently thread-safe facilities for working with IO objects
30
39
 
31
- [Celluloid::IO](https://github.com/celluloid/celluloid-io) uses nio4r to
32
- monitor multiple IO objects from a single Celluloid actor.
33
-
34
- Supported Platforms
35
- -------------------
36
-
37
- nio4r is known to work on the following Ruby implementations:
38
-
39
- * MRI/YARV 1.9.3, 2.0.0, 2.1.0
40
- * JRuby 1.7.x
41
- * Rubinius 2.x
42
- * A pure Ruby implementation based on Kernel.select is also provided
43
-
44
- Platform notes:
45
-
46
- * MRI/YARV and Rubinius implement nio4r with a C extension based on libev,
47
- which provides a high performance binding to native IO APIs
48
- * JRuby uses a Java extension based on the high performance Java NIO subsystem
49
- * A pure Ruby implementation is also provided for Ruby implementations which
50
- don't implement the MRI C extension API
51
-
52
- Usage
53
- -----
40
+ ## Supported platforms
54
41
 
55
- ### Selectors
42
+ * Ruby 2.2.2+
43
+ * Ruby 2.3
44
+ * Ruby 2.4
45
+ * JRuby 9000
56
46
 
57
- The NIO::Selector class is the main API provided by nio4r. Use it where you
58
- might otherwise use Kernel.select, but want to monitor the same set of IO
59
- objects across multiple select calls rather than having to reregister them
60
- every single time:
61
-
62
- ```ruby
63
- require 'nio'
47
+ ## Supported backends
64
48
 
65
- selector = NIO::Selector.new
66
- ```
67
-
68
- To monitor IO objects, attach them to the selector with the NIO::Selector#register
69
- method, monitoring them for read readiness with the :r parameter, write
70
- readiness with the :w parameter, or both with :rw.
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
71
52
 
72
- ```ruby
73
- >> reader, writer = IO.pipe
74
- => [#<IO:0xf30>, #<IO:0xf34>]
75
- >> monitor = selector.register(reader, :r)
76
- => #<NIO::Monitor:0xfbc>
77
- ```
53
+ ## Documentation
78
54
 
79
- After registering an IO object with the selector, you'll get a NIO::Monitor
80
- object which you can use for managing how a particular IO object is being
81
- monitored. Monitors will store an arbitrary value of your choice, which
82
- provides an easy way to implement callbacks:
55
+ [Please see the nio4r wiki](https://github.com/socketry/nio4r/wiki)
56
+ for more detailed documentation and usage notes:
83
57
 
84
- ```ruby
85
- >> monitor = selector.register(reader, :r)
86
- => #<NIO::Monitor:0xfbc>
87
- >> monitor.value = proc { puts "Got some data: #{monitor.io.read_nonblock(4096)}" }
88
- => #<Proc:0x1000@(irb):4>
89
- ```
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
90
62
 
91
- The main method of importance is NIO::Selector#select, which monitors all
92
- registered IO objects and returns an array of monitors that are ready.
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
93
67
 
94
- ```ruby
95
- >> writer << "Hi there!"
96
- => #<IO:0x103c>
97
- >> ready = selector.select
98
- => [#<NIO::Monitor:0xfbc>]
99
- >> ready.each { |m| m.value.call }
100
- Got some data: Hi there!
101
- => [#<NIO::Monitor:0xfbc>]
102
- ```
68
+ See also:
103
69
 
104
- By default, NIO::Selector#select will block indefinitely until one of the IO
105
- objects being monitored becomes ready. However, you can also pass a timeout to
106
- wait in seconds to NIO::Selector#select just like you can with Kernel.select:
70
+ * [YARD API documentation](http://www.rubydoc.info/gems/nio4r/frames)
107
71
 
108
- ```ruby
109
- ready = selector.select(15) # Wait 15 seconds
110
- ```
72
+ ## Non-goals
111
73
 
112
- If a timeout occurs, ready will be nil.
113
-
114
- You can avoid allocating an array each time you call NIO::Selector#select by
115
- passing a block to select. The block will be called for each ready monitor
116
- object, with that object passed as an argument. The number of ready monitors
117
- is returned as a Fixnum:
118
-
119
- ```ruby
120
- >> selector.select { |m| m.value.call }
121
- Got some data: Hi there!
122
- => 1
123
- ```
124
-
125
- When you're done monitoring a particular IO object, just deregister it from
126
- the selector:
127
-
128
- ```ruby
129
- selector.deregister(reader)
130
- ```
131
-
132
- ### Monitors
133
-
134
- Monitors provide methods which let you introspect on why a particular IO
135
- object was selected. These methods are not thread safe unless you are holding
136
- the selector lock (i.e. if you're in a block passed to #select). Only use them
137
- if you aren't concerned with thread safety, or you're within a #select
138
- block:
139
-
140
- - ***#interests***: what this monitor is interested in (:r, :w, or :rw)
141
- - ***#interests=***: change the current interests for a monitor (to :r, :w, or :rw)
142
- - ***#readiness***: what I/O operations the monitored object is ready for
143
- - ***#readable?***: was the IO readable last time it was selected?
144
- - ***#writable?***: was the IO writable last time it was selected?
145
-
146
- Monitors also support a ***#value*** and ***#value=*** method for storing a
147
- handle to an arbitrary object of your choice (e.g. a proc)
148
-
149
- ### Flow Control
150
-
151
- For information on how to compose nio4r selectors inside of event loops,
152
- please read the [Flow Control Guide on the
153
- Wiki](https://github.com/celluloid/nio4r/wiki/Basic-Flow-Control)
154
-
155
- Concurrency
156
- -----------
157
-
158
- nio4r provides internal locking to ensure that it's safe to use from multiple
159
- concurrent threads. Only one thread can select on a NIO::Selector at a given
160
- time, and while a thread is selecting other threads are blocked from
161
- registering or deregistering IO objects. Once a pending select has completed,
162
- requests to register/unregister IO objects will be processed.
163
-
164
- NIO::Selector#wakeup allows one thread to unblock another thread that's in the
165
- middle of an NIO::Selector#select operation. This lets other threads that need
166
- to communicate immediately with the selector unblock it so it can process
167
- other events that it's not presently selecting on.
168
-
169
- What nio4r is not
170
- -----------------
171
-
172
- nio4r is not a full-featured event framework like EventMachine or Cool.io.
74
+ **nio4r** is not a full-featured event framework like [EventMachine] or [Cool.io].
173
75
  Instead, nio4r is the sort of thing you might write a library like that on
174
76
  top of. nio4r provides a minimal API such that individual Ruby implementers
175
77
  may choose to produce optimized versions for their platform, without having
176
78
  to maintain a large codebase.
177
79
 
178
- As of the time of writing, the current implementation is (approximately):
80
+ [EventMachine]: https://github.com/eventmachine/eventmachine
81
+ [Cool.io]: https://coolio.github.io/
179
82
 
180
- * 200 lines of Ruby code
181
- * 700 lines of "custom" C code (not counting libev)
182
- * 400 lines of Java code
183
-
184
- nio4r is also not a replacement for Kinder Gentler IO (KGIO), a set of
185
- advanced Ruby IO APIs. At some point in the future nio4r might provide a
186
- cross-platform implementation that uses KGIO on CRubies, and Java NIO on JRuby,
187
- however this is not the case today.
188
-
189
- License
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
- Includes libev 4.22. Copyright (c) 2007-2015 Marc Alexander Lehmann.
196
- Distributed under the BSD license. See ext/libev/LICENSE for details.
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