lightio 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/lightio/core/backend/nio.rb +2 -0
- data/lib/lightio/core/beam.rb +4 -1
- data/lib/lightio/core/ioloop.rb +2 -1
- data/lib/lightio/library/io.rb +36 -12
- data/lib/lightio/library/mutex.rb +32 -1
- data/lib/lightio/library/socket.rb +10 -0
- data/lib/lightio/library/thread.rb +8 -11
- data/lib/lightio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e60501b7bca5cc445161d405a11e4a7d688de116
|
4
|
+
data.tar.gz: 6068963377b9805a4cc93090d6d14eaba2df280a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9e29908ede0af65b6b8a6d86d7ed88f85de30e6275c7a34917ef3ed3e444ac6df2567de2392b9859daabae6158ead27dc2be4b13669adb0070aa895cae3d8ee
|
7
|
+
data.tar.gz: 391014cc0762ba84b948e9a18efe76377a61dcc6135926eec7c543a93b0921d9e707b52a1b260173a4286a90822716e264c4973c5238f85c2b4da24b0a875235
|
data/Gemfile.lock
CHANGED
data/lib/lightio/core/beam.rb
CHANGED
@@ -49,7 +49,7 @@ module LightIO::Core
|
|
49
49
|
super() {
|
50
50
|
begin
|
51
51
|
@value = yield(*args)
|
52
|
-
rescue
|
52
|
+
rescue Exception => e
|
53
53
|
@error = e
|
54
54
|
end
|
55
55
|
# mark as dead
|
@@ -136,8 +136,11 @@ module LightIO::Core
|
|
136
136
|
#
|
137
137
|
# @return [nil]
|
138
138
|
def pass
|
139
|
+
running = IOloop.current.running
|
139
140
|
schedule = LightIO::Watchers::Schedule.new
|
140
141
|
IOloop.current.wait(schedule)
|
142
|
+
# make sure ioloop run once
|
143
|
+
pass unless running
|
141
144
|
end
|
142
145
|
end
|
143
146
|
|
data/lib/lightio/core/ioloop.rb
CHANGED
@@ -15,7 +15,8 @@ module LightIO::Core
|
|
15
15
|
end
|
16
16
|
|
17
17
|
extend Forwardable
|
18
|
-
def_delegators :@backend, :run, :add_timer, :add_callback, :add_io_wait, :cancel_io_wait, :backend,
|
18
|
+
def_delegators :@backend, :run, :add_timer, :add_callback, :add_io_wait, :cancel_io_wait, :backend,
|
19
|
+
:close, :closed?, :stop, :running
|
19
20
|
|
20
21
|
# Wait a watcher, watcher can be a timer or socket.
|
21
22
|
# see LightIO::Watchers module for detail
|
data/lib/lightio/library/io.rb
CHANGED
@@ -118,16 +118,15 @@ module LightIO::Library
|
|
118
118
|
@io_watcher.wait_readable
|
119
119
|
end
|
120
120
|
|
121
|
-
def io_watcher
|
122
|
-
@io_watcher
|
123
|
-
end
|
124
|
-
|
125
121
|
class << self
|
126
122
|
def open(*args)
|
127
123
|
io = self.new(*args)
|
128
|
-
|
129
|
-
|
130
|
-
|
124
|
+
return io unless block_given?
|
125
|
+
begin
|
126
|
+
yield io
|
127
|
+
ensure
|
128
|
+
io.close if io.respond_to? :close
|
129
|
+
end
|
131
130
|
end
|
132
131
|
|
133
132
|
def pipe(*args)
|
@@ -148,13 +147,19 @@ module LightIO::Library
|
|
148
147
|
read_fds ||= []
|
149
148
|
write_fds ||= []
|
150
149
|
loop do
|
151
|
-
# clear io watcher status
|
152
|
-
read_fds.each {|fd| fd
|
153
|
-
write_fds.each {|fd| fd
|
150
|
+
# make sure io registered, then clear io watcher status
|
151
|
+
read_fds.each {|fd| get_io_watcher(fd).tap {|io| io.readable?; io.clear_status}}
|
152
|
+
write_fds.each {|fd| get_io_watcher(fd).tap {|io| io.writable?; io.clear_status}}
|
154
153
|
# run ioloop once
|
155
154
|
LightIO.sleep 0
|
156
|
-
r_fds = read_fds.select {|fd|
|
157
|
-
|
155
|
+
r_fds = read_fds.select {|fd|
|
156
|
+
io = convert_to_io(fd)
|
157
|
+
io.closed? ? raise(IOError, 'closed stream') : get_io_watcher(io).readable?
|
158
|
+
}
|
159
|
+
w_fds = write_fds.select {|fd|
|
160
|
+
io = convert_to_io(fd)
|
161
|
+
io.closed? ? raise(IOError, 'closed stream') : get_io_watcher(io).writable?
|
162
|
+
}
|
158
163
|
e_fds = []
|
159
164
|
if r_fds.empty? && w_fds.empty?
|
160
165
|
if timeout && Time.now - timer > timeout
|
@@ -165,6 +170,25 @@ module LightIO::Library
|
|
165
170
|
end
|
166
171
|
end
|
167
172
|
end
|
173
|
+
|
174
|
+
private
|
175
|
+
def convert_to_io(io)
|
176
|
+
unless io.respond_to?(:to_io)
|
177
|
+
raise TypeError, "no implicit conversion of #{io.class} into IO"
|
178
|
+
end
|
179
|
+
to_io = io.to_io
|
180
|
+
unless to_io.is_a?(IO)
|
181
|
+
raise TypeError, "can't convert #{io.class} to IO (#{io.class}#to_io gives #{to_io.class})"
|
182
|
+
end
|
183
|
+
to_io
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_io_watcher(io)
|
187
|
+
unless io.is_a?(IO)
|
188
|
+
io = convert_to_io(io)
|
189
|
+
end
|
190
|
+
io.instance_variable_get(:@io_watcher)
|
191
|
+
end
|
168
192
|
end
|
169
193
|
end
|
170
194
|
end
|
@@ -4,7 +4,7 @@ module LightIO::Library
|
|
4
4
|
class Thread
|
5
5
|
class Mutex
|
6
6
|
def initialize
|
7
|
-
@queue = Queue.new
|
7
|
+
@queue = LightIO::Library::Queue.new
|
8
8
|
@queue << true
|
9
9
|
@locked_thread = nil
|
10
10
|
end
|
@@ -56,7 +56,38 @@ module LightIO::Library
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
class ConditionVariable
|
61
|
+
def initialize
|
62
|
+
@queue = LightIO::Library::Queue.new
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def broadcast
|
67
|
+
signal until @queue.num_waiting == 0
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
def signal
|
72
|
+
@queue << true unless @queue.num_waiting == 0
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def wait(mutex, timeout=nil)
|
77
|
+
mutex.unlock
|
78
|
+
begin
|
79
|
+
LightIO::Library::Timeout.timeout(timeout) do
|
80
|
+
@queue.pop
|
81
|
+
end
|
82
|
+
rescue Timeout::Error
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
mutex.lock
|
86
|
+
self
|
87
|
+
end
|
88
|
+
end
|
59
89
|
end
|
60
90
|
|
61
91
|
Mutex = Thread::Mutex
|
92
|
+
ConditionVariable = Thread::ConditionVariable
|
62
93
|
end
|
@@ -96,6 +96,11 @@ module LightIO::Library
|
|
96
96
|
[self.class._wrap(socket), Addrinfo._wrap(addrinfo)]
|
97
97
|
end
|
98
98
|
|
99
|
+
def accept_nonblock(*args)
|
100
|
+
socket, addrinfo = @io.accept_nonblock(*args)
|
101
|
+
[self.class._wrap(socket), Addrinfo._wrap(addrinfo)]
|
102
|
+
end
|
103
|
+
|
99
104
|
def sys_accept
|
100
105
|
@io_watcher.wait_readable
|
101
106
|
@io.sys_accept
|
@@ -181,6 +186,11 @@ module LightIO::Library
|
|
181
186
|
TCPSocket._wrap(socket)
|
182
187
|
end
|
183
188
|
|
189
|
+
def accept_nonblock(*args)
|
190
|
+
socket = @io.accept_nonblock(*args)
|
191
|
+
TCPSocket._wrap(socket)
|
192
|
+
end
|
193
|
+
|
184
194
|
def sys_accept
|
185
195
|
@io_watcher.wait_readable
|
186
196
|
@io.sys_accept
|
@@ -51,13 +51,6 @@ module LightIO::Library
|
|
51
51
|
obj.public_send method, *args
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
|
-
def fallback_thread_class_methods(*methods)
|
56
|
-
methods.each {|m| fallback_method(RAW_THREAD.main, m, "This method is fallback to native Thread class,"\
|
57
|
-
" it may cause unexpected behaviour,"\
|
58
|
-
" open issues on https://github.com/socketry/lightio/issues"\
|
59
|
-
" if this behaviour not approach you purpose")}
|
60
|
-
end
|
61
54
|
end
|
62
55
|
|
63
56
|
include ClassMethods
|
@@ -76,10 +69,15 @@ module LightIO::Library
|
|
76
69
|
|
77
70
|
class << self
|
78
71
|
extend Forwardable
|
79
|
-
def_delegators :'LightIO::Library::Thread::RAW_THREAD',
|
72
|
+
def_delegators :'LightIO::Library::Thread::RAW_THREAD',
|
73
|
+
:DEBUG,
|
74
|
+
:DEBUG=,
|
75
|
+
:handle_interrupt,
|
76
|
+
:abort_on_exception,
|
77
|
+
:abort_on_exception=,
|
78
|
+
:pending_interrupt?
|
80
79
|
|
81
80
|
include FallbackHelper
|
82
|
-
fallback_thread_class_methods :abort_on_exception, :abort_on_exception=
|
83
81
|
|
84
82
|
def fork(*args, &blk)
|
85
83
|
obj = allocate
|
@@ -155,8 +153,7 @@ module LightIO::Library
|
|
155
153
|
|
156
154
|
fallback_main_thread_methods :abort_on_exception,
|
157
155
|
:abort_on_exception=,
|
158
|
-
:
|
159
|
-
:pending_interrupt,
|
156
|
+
:pending_interrupt?,
|
160
157
|
:add_trace_func,
|
161
158
|
:backtrace,
|
162
159
|
:backtrace_locations,
|
data/lib/lightio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiang Jinyang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|