celluloid-io 0.13.0.pre2 → 0.13.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.
- data/CHANGES.md +2 -2
- data/README.md +43 -134
- data/celluloid-io.gemspec +1 -1
- data/lib/celluloid/io/version.rb +1 -1
- metadata +8 -10
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-

|
2
|
-
|
1
|
+

|
2
|
+
================
|
3
3
|
[](http://rubygems.org/gems/celluloid-io)
|
4
4
|
[](http://travis-ci.org/celluloid/celluloid-io)
|
5
5
|
[](https://gemnasium.com/celluloid/celluloid-io)
|
@@ -36,140 +36,46 @@ to monitor IO objects, which provides cross-platform and cross-Ruby
|
|
36
36
|
implementation access to high-performance system calls such as epoll
|
37
37
|
and kqueue.
|
38
38
|
|
39
|
-
Like Celluloid::IO? [Join the Google Group](http://groups.google.com/group/celluloid-ruby)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
to start off using blocking I/O until you understand the fundamentals of
|
69
|
-
Celluloid and have encountered one of the above reasons for switching
|
70
|
-
over to Celluloid::IO.
|
39
|
+
Like Celluloid::IO? [Join the Celluloid Google Group](http://groups.google.com/group/celluloid-ruby)
|
40
|
+
|
41
|
+
Documentation
|
42
|
+
-------------
|
43
|
+
|
44
|
+
[Please see the Celluloid::IO Wiki](https://github.com/celluloid/celluloid-io/wiki)
|
45
|
+
for more detailed documentation and usage notes.
|
46
|
+
|
47
|
+
[YARD documentation](http://rubydoc.info/github/celluloid/celluloid-io/frames)
|
48
|
+
is also available
|
49
|
+
|
50
|
+
Installation
|
51
|
+
------------
|
52
|
+
|
53
|
+
Add this line to your application's Gemfile:
|
54
|
+
|
55
|
+
gem 'celluloid-io'
|
56
|
+
|
57
|
+
And then execute:
|
58
|
+
|
59
|
+
$ bundle
|
60
|
+
|
61
|
+
Or install it yourself as:
|
62
|
+
|
63
|
+
$ gem install celluloid-io
|
64
|
+
|
65
|
+
Inside of your Ruby program, require Celluloid::IO with:
|
66
|
+
|
67
|
+
require 'celluloid/io'
|
71
68
|
|
72
69
|
Supported Platforms
|
73
70
|
-------------------
|
74
71
|
|
75
|
-
Celluloid::IO
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
Usage
|
83
|
-
-----
|
84
|
-
|
85
|
-
To use Celluloid::IO, define a normal Ruby class that includes Celluloid::IO.
|
86
|
-
The following is an example of an echo server:
|
87
|
-
|
88
|
-
```ruby
|
89
|
-
require 'celluloid/io'
|
90
|
-
|
91
|
-
class EchoServer
|
92
|
-
include Celluloid::IO
|
93
|
-
|
94
|
-
def initialize(host, port)
|
95
|
-
puts "*** Starting echo server on #{host}:#{port}"
|
96
|
-
|
97
|
-
# Since we included Celluloid::IO, we're actually making a
|
98
|
-
# Celluloid::IO::TCPServer here
|
99
|
-
@server = TCPServer.new(host, port)
|
100
|
-
run!
|
101
|
-
end
|
102
|
-
|
103
|
-
def finalize
|
104
|
-
@server.close if @server
|
105
|
-
end
|
106
|
-
|
107
|
-
def run
|
108
|
-
loop { handle_connection! @server.accept }
|
109
|
-
end
|
110
|
-
|
111
|
-
def handle_connection(socket)
|
112
|
-
_, port, host = socket.peeraddr
|
113
|
-
puts "*** Received connection from #{host}:#{port}"
|
114
|
-
loop { socket.write socket.readpartial(4096) }
|
115
|
-
rescue EOFError
|
116
|
-
puts "*** #{host}:#{port} disconnected"
|
117
|
-
end
|
118
|
-
end
|
119
|
-
```
|
120
|
-
|
121
|
-
The very first thing including *Celluloid::IO* does is also include the
|
122
|
-
*Celluloid* module, which promotes objects of this class to concurrent Celluloid
|
123
|
-
actors each running in their own thread. Before trying to use Celluloid::IO
|
124
|
-
you may want to [familiarize yourself with Celluloid in general](https://github.com/celluloid/celluloid/).
|
125
|
-
Celluloid actors can each be thought of as being event loops. Celluloid::IO actors
|
126
|
-
are heavier but have capabilities similar to other event loop-driven frameworks.
|
127
|
-
|
128
|
-
While this looks like a normal Ruby TCP server, there aren't any threads, so
|
129
|
-
you might expect this server can only handle one connection at a time.
|
130
|
-
However, this is all you need to do to build servers that handle as many
|
131
|
-
connections as you want, and it happens all within a single thread.
|
132
|
-
|
133
|
-
The magic in this server which allows it to handle multiple connections
|
134
|
-
comes in three forms:
|
135
|
-
|
136
|
-
* __Replacement classes:__ Celluloid::IO includes replacements for the core
|
137
|
-
TCPServer and TCPSocket classes which automatically use an evented mode
|
138
|
-
inside of Celluloid::IO actors. They're named Celluloid::IO::TCPServer and
|
139
|
-
Celluloid::IO::TCPSocket, so they're automatically available inside
|
140
|
-
your class when you include Celluloid::IO.
|
141
|
-
|
142
|
-
* __Asynchronous method calls:__ You may have noticed that while the methods
|
143
|
-
of EchoServer are named *run* and *handle_connection*, they're invoked as
|
144
|
-
*run!* and *handle_connection!*. This queues these methods to be executed
|
145
|
-
after the current method is complete. You can queue up as many methods as
|
146
|
-
you want, allowing asynchronous operation similar to the "call later" or
|
147
|
-
"next tick" feature of Twisted, EventMachine, and Node. This echo server
|
148
|
-
first kicks off a background task for accepting connections on the server
|
149
|
-
socket, then kicks off a background task for each connection.
|
150
|
-
|
151
|
-
* __Reactor + Fibers:__ Celluloid::IO is a combination of Actor and Reactor
|
152
|
-
concepts. The blocking mechanism used by the mailboxes of Celluloid::IO
|
153
|
-
actors is an [nio4r-powered reactor](https://github.com/celluloid/celluloid-io/blob/master/lib/celluloid/io/reactor.rb).
|
154
|
-
When the current task needs to make a blocking I/O call, it first makes
|
155
|
-
a non-blocking attempt, and if the socket isn't ready the current task
|
156
|
-
is suspended until the reactor detects the operation is ready and resumes
|
157
|
-
the suspended task.
|
158
|
-
|
159
|
-
The result is an API for doing evented I/O that looks identical to doing
|
160
|
-
synchronous I/O. Adapting existing synchronous libraries to using evented I/O
|
161
|
-
is as simple as having them use one of Celluloid::IO's provided replacement
|
162
|
-
classes instead of the core Ruby TCPSocket and TCPServer classes.
|
163
|
-
|
164
|
-
Status
|
165
|
-
------
|
166
|
-
|
167
|
-
The rudiments of TCPServer TCPSocket, and UNIXSocket are in place and ready to use. It is now
|
168
|
-
fully nonblocking, including DNS resolution, which effectively makes Celluloid::IO
|
169
|
-
feature complete as a nonblocking I/O system.
|
170
|
-
|
171
|
-
Basic UDPSocket support is in place. On JRuby, recvfrom makes a blocking call
|
172
|
-
as the underlying recvfrom_nonblock call is not supported by JRuby.
|
72
|
+
Celluloid::IO works on Ruby 1.9.3, 2.0.0, JRuby 1.6+, and Rubinius 2.0.
|
73
|
+
|
74
|
+
JRuby or Rubinius are the preferred platforms as they support true thread-level
|
75
|
+
parallelism when executing Ruby code, whereas MRI/YARV is constrained by a global
|
76
|
+
interpreter lock (GIL) and can only execute one thread at a time.
|
77
|
+
|
78
|
+
Celluloid::IO requires Ruby 1.9 mode on all interpreters.
|
173
79
|
|
174
80
|
Contributing to Celluloid::IO
|
175
81
|
-----------------------------
|
@@ -182,8 +88,11 @@ Contributing to Celluloid::IO
|
|
182
88
|
License
|
183
89
|
-------
|
184
90
|
|
185
|
-
Copyright (c)
|
91
|
+
Copyright (c) 2013 Tony Arcieri. Distributed under the MIT License. See
|
186
92
|
LICENSE.txt for further details.
|
187
93
|
|
188
|
-
Contains code originally from the RubySpec project also under the MIT License
|
94
|
+
Contains code originally from the RubySpec project also under the MIT License.
|
189
95
|
Copyright (c) 2008 Engine Yard, Inc. All rights reserved.
|
96
|
+
|
97
|
+
Contains code originally from the 'OpenSSL for Ruby 2' project released under
|
98
|
+
the Ruby license. Copyright (C) 2001 GOTOU YUUZOU. All rights reserved.
|
data/celluloid-io.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Celluloid::IO::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'celluloid', '>= 0.13.0
|
18
|
+
gem.add_dependency 'celluloid', '>= 0.13.0'
|
19
19
|
gem.add_dependency 'nio4r', '>= 0.4.0'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'rake'
|
data/lib/celluloid/io/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.13.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tony Arcieri
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.13.0
|
21
|
+
version: 0.13.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.0
|
29
|
+
version: 0.13.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: nio4r
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,15 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
190
|
- - ! '>='
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: '0'
|
193
|
-
segments:
|
194
|
-
- 0
|
195
|
-
hash: -1245022308244925467
|
196
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
194
|
none: false
|
198
195
|
requirements:
|
199
|
-
- - ! '
|
196
|
+
- - ! '>='
|
200
197
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
198
|
+
version: '0'
|
202
199
|
requirements: []
|
203
200
|
rubyforge_project:
|
204
201
|
rubygems_version: 1.8.23
|
@@ -222,3 +219,4 @@ test_files:
|
|
222
219
|
- spec/fixtures/server.crt
|
223
220
|
- spec/fixtures/server.key
|
224
221
|
- spec/spec_helper.rb
|
222
|
+
has_rdoc:
|