libuv 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/libuv/ext/ext.rb +13 -2
- data/lib/libuv/reactor.rb +20 -20
- data/lib/libuv/version.rb +1 -1
- data/spec/async_spec.rb +13 -8
- data/spec/defer_spec.rb +5 -0
- data/spec/dns_spec.rb +7 -3
- 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: b10a0bc452c1191da75b68559a2938ac09284f85
|
4
|
+
data.tar.gz: 60d8591279de58b4de765a46ecf3e4352f271fd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9385371508feaf33ba6a28b3566063746383f540f6959a8466cc05188874b29ba69ecfba96ee9cf038ef23bf814e990d51fe6f4e06f9f7282481fc3595f92ec7
|
7
|
+
data.tar.gz: 10d0fc2affa3b408ec867d769dea18fcead4c17f49fa73802e58718785cab5cabff58a9d45f88d6e2c4bb6e2414e4dbcf24770435889770cc6cf941a592c1715
|
data/lib/libuv/ext/ext.rb
CHANGED
@@ -28,10 +28,12 @@ module Libuv
|
|
28
28
|
|
29
29
|
|
30
30
|
begin
|
31
|
+
lib_path = ::File.expand_path('../', path_to_internal_libuv)
|
32
|
+
|
31
33
|
# bias the library discovery to a path inside the gem first, then
|
32
34
|
# to the usual system paths
|
33
35
|
paths = [
|
34
|
-
|
36
|
+
lib_path,
|
35
37
|
'/usr/local/lib',
|
36
38
|
'/opt/local/lib',
|
37
39
|
'/usr/lib64'
|
@@ -42,7 +44,16 @@ module Libuv
|
|
42
44
|
# Primarily a dev platform so that is OK
|
43
45
|
paths.unshift "#{ENV['HOME']}/lib"
|
44
46
|
elsif FFI::Platform.windows?
|
45
|
-
|
47
|
+
module Kernel32
|
48
|
+
extend FFI::Library
|
49
|
+
ffi_lib 'Kernel32'
|
50
|
+
|
51
|
+
attach_function :add_dll_dir, :AddDllDirectory,
|
52
|
+
[ :buffer_in ], :pointer
|
53
|
+
end
|
54
|
+
# This ensures that externally loaded libraries like the libcouchbase gem
|
55
|
+
# will always use the same binary image and not load a second into memory
|
56
|
+
Kernel32.add_dll_dir "#{lib_path}\0".encode("UTF-16LE")
|
46
57
|
else # UNIX
|
47
58
|
# TODO:: ??
|
48
59
|
end
|
data/lib/libuv/reactor.rb
CHANGED
@@ -8,7 +8,6 @@ module Libuv
|
|
8
8
|
extend Accessors
|
9
9
|
|
10
10
|
|
11
|
-
REACTORS = ::Concurrent::Map.new
|
12
11
|
CRITICAL = ::Mutex.new
|
13
12
|
|
14
13
|
|
@@ -47,7 +46,7 @@ module Libuv
|
|
47
46
|
#
|
48
47
|
# @return [::Libuv::Reactor | nil]
|
49
48
|
def current
|
50
|
-
|
49
|
+
Thread.current.thread_variable_get(:reactor)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
extend ClassMethods
|
@@ -89,7 +88,7 @@ module Libuv
|
|
89
88
|
|
90
89
|
# Notify of errors
|
91
90
|
@throw_on_exit = nil
|
92
|
-
@reactor_notify = proc { |error|
|
91
|
+
@reactor_notify_default = @reactor_notify = proc { |error|
|
93
92
|
@throw_on_exit = error
|
94
93
|
}
|
95
94
|
end
|
@@ -103,8 +102,8 @@ module Libuv
|
|
103
102
|
def noop; end
|
104
103
|
|
105
104
|
def stop_cb
|
106
|
-
|
107
|
-
@
|
105
|
+
Thread.current.thread_variable_set(:reactor, nil)
|
106
|
+
@reactor_running = false
|
108
107
|
|
109
108
|
::Libuv::Ext.stop(@pointer)
|
110
109
|
end
|
@@ -157,12 +156,12 @@ module Libuv
|
|
157
156
|
# @yieldparam promise [::Libuv::Q::Promise] Yields a promise that can be used for logging unhandled
|
158
157
|
# exceptions on the reactor.
|
159
158
|
def run(run_type = :UV_RUN_DEFAULT)
|
160
|
-
if @
|
159
|
+
if not @reactor_running
|
161
160
|
begin
|
162
|
-
@
|
163
|
-
raise 'only one reactor allowed per-thread' if
|
161
|
+
@reactor_running = true
|
162
|
+
raise 'only one reactor allowed per-thread' if Thread.current.thread_variable_get(:reactor)
|
164
163
|
|
165
|
-
|
164
|
+
Thread.current.thread_variable_set(:reactor, @reactor)
|
166
165
|
@throw_on_exit = nil
|
167
166
|
|
168
167
|
if block_given?
|
@@ -178,8 +177,8 @@ module Libuv
|
|
178
177
|
@run_count += 1
|
179
178
|
::Libuv::Ext.run(@pointer, run_type) # This is blocking
|
180
179
|
ensure
|
181
|
-
|
182
|
-
@
|
180
|
+
Thread.current.thread_variable_set(:reactor, nil)
|
181
|
+
@reactor_running = false
|
183
182
|
@run_queue.clear
|
184
183
|
end
|
185
184
|
|
@@ -219,7 +218,7 @@ module Libuv
|
|
219
218
|
#
|
220
219
|
# @return [::Libuv::Q::Promise]
|
221
220
|
def notifier(callback = nil, &blk)
|
222
|
-
@reactor_notify = callback || blk
|
221
|
+
@reactor_notify = callback || blk || @reactor_notify_default
|
223
222
|
self
|
224
223
|
end
|
225
224
|
|
@@ -263,7 +262,13 @@ module Libuv
|
|
263
262
|
def finally(*promises)
|
264
263
|
Q.finally(@reactor, *promises)
|
265
264
|
end
|
266
|
-
|
265
|
+
|
266
|
+
# Creates a promise that is resolved as rejected with the specified reason. This api should be
|
267
|
+
# used to forward rejection in a chain of promises. If you are dealing with the last promise in
|
268
|
+
# a promise chain, you don't need to worry about it.
|
269
|
+
def reject(reason)
|
270
|
+
Q.reject(@reactor, reason)
|
271
|
+
end
|
267
272
|
|
268
273
|
# forces reactor time update, useful for getting more granular times
|
269
274
|
#
|
@@ -507,19 +512,14 @@ module Libuv
|
|
507
512
|
#
|
508
513
|
# @return [Boolean]
|
509
514
|
def reactor_thread?
|
510
|
-
|
515
|
+
self == Thread.current.thread_variable_get(:reactor)
|
511
516
|
end
|
512
517
|
|
513
|
-
# Exposed to allow joining on the thread, when run in a multithreaded environment. Performing other actions on the thread has undefined semantics (read: a dangerous endevor).
|
514
|
-
#
|
515
|
-
# @return [Thread]
|
516
|
-
attr_reader :reactor_thread
|
517
|
-
|
518
518
|
# Tells you whether the Libuv reactor reactor is currently running.
|
519
519
|
#
|
520
520
|
# @return [Boolean]
|
521
521
|
def reactor_running?
|
522
|
-
|
522
|
+
@reactor_running
|
523
523
|
end
|
524
524
|
alias_method :running?, :reactor_running?
|
525
525
|
end
|
data/lib/libuv/version.rb
CHANGED
data/spec/async_spec.rb
CHANGED
@@ -16,19 +16,24 @@ describe Libuv::Async do
|
|
16
16
|
|
17
17
|
@reactor.all(@server, @client, @timeout).catch do |reason|
|
18
18
|
@general_failure << reason.inspect
|
19
|
-
|
19
|
+
puts "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
@reactor.notifier do |error, context|
|
23
|
+
begin
|
24
|
+
puts "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
25
|
+
rescue Exception
|
26
|
+
puts 'error in logger'
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
30
|
+
|
31
|
+
after :each do
|
32
|
+
@reactor.notifier
|
33
|
+
end
|
22
34
|
|
23
35
|
it "Should call the async function from the thread pool stopping the counter" do
|
24
36
|
@reactor.run { |reactor|
|
25
|
-
reactor.notifier do |error, context|
|
26
|
-
begin
|
27
|
-
p "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
28
|
-
rescue Exception
|
29
|
-
p 'error in logger'
|
30
|
-
end
|
31
|
-
end
|
32
37
|
|
33
38
|
@count = 0
|
34
39
|
|
data/spec/defer_spec.rb
CHANGED
@@ -5,6 +5,7 @@ describe Libuv::Q do
|
|
5
5
|
|
6
6
|
before :each do
|
7
7
|
@reactor = Libuv::Reactor.default
|
8
|
+
@reactor.notifier {}
|
8
9
|
@deferred = @reactor.defer
|
9
10
|
@promise = @deferred.promise
|
10
11
|
@log = []
|
@@ -12,6 +13,10 @@ describe Libuv::Q do
|
|
12
13
|
@reactor.stop
|
13
14
|
}
|
14
15
|
end
|
16
|
+
|
17
|
+
after :each do
|
18
|
+
@reactor.notifier
|
19
|
+
end
|
15
20
|
|
16
21
|
|
17
22
|
describe 'resolve' do
|
data/spec/dns_spec.rb
CHANGED
@@ -9,9 +9,9 @@ describe Libuv::Dns do
|
|
9
9
|
@reactor = Libuv::Reactor.default
|
10
10
|
@reactor.notifier do |error, context|
|
11
11
|
begin
|
12
|
-
|
12
|
+
puts "Log called: #{context}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
13
13
|
rescue Exception
|
14
|
-
|
14
|
+
puts 'error in logger'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
@timeout = @reactor.timer do
|
@@ -22,9 +22,13 @@ describe Libuv::Dns do
|
|
22
22
|
|
23
23
|
@reactor.all(@server, @client, @timeout).catch do |reason|
|
24
24
|
@general_failure << reason.inspect
|
25
|
-
|
25
|
+
puts "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
after :each do
|
30
|
+
@reactor.notifier
|
31
|
+
end
|
28
32
|
|
29
33
|
it "should resolve localhost using IP4", :network => true do
|
30
34
|
@reactor.run { |reactor|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libuv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|