libuv 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/.gitignore +17 -17
- data/.gitmodules +3 -3
- data/.rspec +1 -1
- data/.travis.yml +16 -16
- data/Gemfile +4 -4
- data/LICENSE +23 -23
- data/README.md +82 -82
- data/Rakefile +31 -31
- data/lib/libuv.rb +54 -54
- data/lib/libuv/async.rb +47 -47
- data/lib/libuv/check.rb +55 -55
- data/lib/libuv/dns.rb +85 -85
- data/lib/libuv/error.rb +73 -70
- data/lib/libuv/ext/ext.rb +258 -258
- data/lib/libuv/ext/platform/darwin_x64.rb +23 -23
- data/lib/libuv/ext/platform/linux.rb +7 -7
- data/lib/libuv/ext/platform/unix.rb +29 -29
- data/lib/libuv/ext/platform/windows.rb +40 -40
- data/lib/libuv/ext/tasks.rb +29 -29
- data/lib/libuv/ext/tasks/mac.rb +23 -23
- data/lib/libuv/ext/tasks/unix.rb +23 -23
- data/lib/libuv/ext/tasks/win.rb +11 -11
- data/lib/libuv/ext/types.rb +238 -238
- data/lib/libuv/file.rb +191 -191
- data/lib/libuv/filesystem.rb +232 -232
- data/lib/libuv/fs_event.rb +31 -31
- data/lib/libuv/handle.rb +85 -85
- data/lib/libuv/idle.rb +56 -56
- data/lib/libuv/loop.rb +387 -385
- data/lib/libuv/mixins/assertions.rb +23 -23
- data/lib/libuv/mixins/fs_checks.rb +55 -55
- data/lib/libuv/mixins/listener.rb +34 -34
- data/lib/libuv/mixins/net.rb +40 -40
- data/lib/libuv/mixins/resource.rb +27 -27
- data/lib/libuv/mixins/stream.rb +154 -154
- data/lib/libuv/pipe.rb +197 -197
- data/lib/libuv/prepare.rb +56 -56
- data/lib/libuv/signal.rb +51 -51
- data/lib/libuv/tcp.rb +317 -315
- data/lib/libuv/timer.rb +91 -91
- data/lib/libuv/tty.rb +37 -37
- data/lib/libuv/udp.rb +224 -224
- data/lib/libuv/version.rb +3 -3
- data/lib/libuv/work.rb +75 -75
- data/libuv.gemspec +56 -56
- data/spec/async_spec.rb +60 -60
- data/spec/cpu_spec.rb +10 -10
- data/spec/defer_spec.rb +980 -980
- data/spec/dns_spec.rb +90 -90
- data/spec/filesystem_spec.rb +124 -124
- data/spec/idle_spec.rb +56 -56
- data/spec/pipe_spec.rb +160 -160
- data/spec/tcp_spec.rb +267 -267
- metadata +24 -30
data/spec/dns_spec.rb
CHANGED
@@ -1,90 +1,90 @@
|
|
1
|
-
require 'libuv'
|
2
|
-
|
3
|
-
|
4
|
-
describe Libuv::Dns do
|
5
|
-
before :each do
|
6
|
-
@log = []
|
7
|
-
@general_failure = []
|
8
|
-
|
9
|
-
@loop = Libuv::Loop.new
|
10
|
-
@timeout = @loop.timer do
|
11
|
-
@loop.stop
|
12
|
-
@general_failure << "test timed out"
|
13
|
-
end
|
14
|
-
@timeout.start(5000)
|
15
|
-
|
16
|
-
@loop.all(@server, @client, @timeout).catch do |reason|
|
17
|
-
@general_failure << reason.inspect
|
18
|
-
p "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should resolve localhost using IP4", :network => true do
|
23
|
-
@loop.run { |logger|
|
24
|
-
logger.progress do |level, errorid, error|
|
25
|
-
begin
|
26
|
-
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
27
|
-
rescue Exception
|
28
|
-
p 'error in logger'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
@loop.lookup('localhost').then proc { |addrinfo|
|
33
|
-
@result = addrinfo[0][0]
|
34
|
-
@loop.stop
|
35
|
-
}, proc { |err|
|
36
|
-
@general_failure << err
|
37
|
-
@loop.stop
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
@general_failure.should == []
|
42
|
-
@result.should == '127.0.0.1'
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should resolve localhost using IP6", :network => true do
|
46
|
-
@loop.run { |logger|
|
47
|
-
logger.progress do |level, errorid, error|
|
48
|
-
begin
|
49
|
-
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
50
|
-
rescue Exception
|
51
|
-
p 'error in logger'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
@loop.lookup('localhost', :IPv6).then proc { |addrinfo|
|
56
|
-
@result = addrinfo[0][0]
|
57
|
-
@loop.stop
|
58
|
-
}, proc { |err|
|
59
|
-
@general_failure << err
|
60
|
-
@loop.stop
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
@general_failure.should == []
|
65
|
-
@result.should == '::1'
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should resolve loop back" do
|
69
|
-
@loop.run { |logger|
|
70
|
-
logger.progress do |level, errorid, error|
|
71
|
-
begin
|
72
|
-
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
73
|
-
rescue Exception
|
74
|
-
p 'error in logger'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
@loop.lookup('127.0.0.1').then proc { |addrinfo|
|
79
|
-
@result = addrinfo[0][0]
|
80
|
-
@loop.stop
|
81
|
-
}, proc { |err|
|
82
|
-
@general_failure << err
|
83
|
-
@loop.stop
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
@general_failure.should == []
|
88
|
-
@result.should == '127.0.0.1'
|
89
|
-
end
|
90
|
-
end
|
1
|
+
require 'libuv'
|
2
|
+
|
3
|
+
|
4
|
+
describe Libuv::Dns do
|
5
|
+
before :each do
|
6
|
+
@log = []
|
7
|
+
@general_failure = []
|
8
|
+
|
9
|
+
@loop = Libuv::Loop.new
|
10
|
+
@timeout = @loop.timer do
|
11
|
+
@loop.stop
|
12
|
+
@general_failure << "test timed out"
|
13
|
+
end
|
14
|
+
@timeout.start(5000)
|
15
|
+
|
16
|
+
@loop.all(@server, @client, @timeout).catch do |reason|
|
17
|
+
@general_failure << reason.inspect
|
18
|
+
p "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should resolve localhost using IP4", :network => true do
|
23
|
+
@loop.run { |logger|
|
24
|
+
logger.progress do |level, errorid, error|
|
25
|
+
begin
|
26
|
+
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
27
|
+
rescue Exception
|
28
|
+
p 'error in logger'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
@loop.lookup('localhost').then proc { |addrinfo|
|
33
|
+
@result = addrinfo[0][0]
|
34
|
+
@loop.stop
|
35
|
+
}, proc { |err|
|
36
|
+
@general_failure << err
|
37
|
+
@loop.stop
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
@general_failure.should == []
|
42
|
+
@result.should == '127.0.0.1'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should resolve localhost using IP6", :network => true do
|
46
|
+
@loop.run { |logger|
|
47
|
+
logger.progress do |level, errorid, error|
|
48
|
+
begin
|
49
|
+
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
50
|
+
rescue Exception
|
51
|
+
p 'error in logger'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@loop.lookup('localhost', :IPv6).then proc { |addrinfo|
|
56
|
+
@result = addrinfo[0][0]
|
57
|
+
@loop.stop
|
58
|
+
}, proc { |err|
|
59
|
+
@general_failure << err
|
60
|
+
@loop.stop
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
@general_failure.should == []
|
65
|
+
@result.should == '::1'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should resolve loop back" do
|
69
|
+
@loop.run { |logger|
|
70
|
+
logger.progress do |level, errorid, error|
|
71
|
+
begin
|
72
|
+
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
73
|
+
rescue Exception
|
74
|
+
p 'error in logger'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
@loop.lookup('127.0.0.1').then proc { |addrinfo|
|
79
|
+
@result = addrinfo[0][0]
|
80
|
+
@loop.stop
|
81
|
+
}, proc { |err|
|
82
|
+
@general_failure << err
|
83
|
+
@loop.stop
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
@general_failure.should == []
|
88
|
+
@result.should == '127.0.0.1'
|
89
|
+
end
|
90
|
+
end
|
data/spec/filesystem_spec.rb
CHANGED
@@ -1,124 +1,124 @@
|
|
1
|
-
require 'libuv'
|
2
|
-
require 'thread'
|
3
|
-
|
4
|
-
|
5
|
-
describe Libuv::Filesystem do
|
6
|
-
before :each do
|
7
|
-
@log = []
|
8
|
-
@general_failure = []
|
9
|
-
|
10
|
-
@loop = Libuv::Loop.new
|
11
|
-
@filesystem = @loop.filesystem
|
12
|
-
@timeout = @loop.timer do
|
13
|
-
@loop.stop
|
14
|
-
@general_failure << "test timed out"
|
15
|
-
end
|
16
|
-
@timeout.start(4000)
|
17
|
-
|
18
|
-
@logger = proc { |level, errorid, error|
|
19
|
-
begin
|
20
|
-
@general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
21
|
-
rescue Exception
|
22
|
-
@general_failure << 'error in logger'
|
23
|
-
end
|
24
|
-
}
|
25
|
-
|
26
|
-
@thefile = "test-file.txt"
|
27
|
-
|
28
|
-
@loop.all(@filesystem, @timeout).catch do |reason|
|
29
|
-
@general_failure << reason.inspect
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe 'directory navigation' do
|
34
|
-
it "should list the contents of a folder" do
|
35
|
-
@loop.run { |logger|
|
36
|
-
logger.progress &@logger
|
37
|
-
|
38
|
-
currentDir = Dir.pwd
|
39
|
-
listing = @filesystem.readdir(currentDir)
|
40
|
-
listing.then do |result|
|
41
|
-
@log = result
|
42
|
-
end
|
43
|
-
listing.catch do |error|
|
44
|
-
@general_failure << error
|
45
|
-
end
|
46
|
-
listing.finally do
|
47
|
-
@loop.stop
|
48
|
-
end
|
49
|
-
}
|
50
|
-
|
51
|
-
@general_failure.should == []
|
52
|
-
(@log.length > 0).should == true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'file manipulation' do
|
57
|
-
it "should create and write to a file" do
|
58
|
-
@loop.run { |logger|
|
59
|
-
logger.progress &@logger
|
60
|
-
|
61
|
-
file = @loop.file(@thefile, File::CREAT|File::WRONLY)
|
62
|
-
file.progress do
|
63
|
-
file.write('write some data to a file').then do
|
64
|
-
file.chmod(777).then do
|
65
|
-
file.close
|
66
|
-
@loop.stop
|
67
|
-
@log = :success
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
file.catch do |error|
|
72
|
-
@general_failure << error
|
73
|
-
file.close
|
74
|
-
@loop.stop
|
75
|
-
end
|
76
|
-
}
|
77
|
-
|
78
|
-
@general_failure.should == []
|
79
|
-
@log.should == :success
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should read from a file" do
|
83
|
-
@loop.run { |logger|
|
84
|
-
logger.progress &@logger
|
85
|
-
|
86
|
-
file = @loop.file(@thefile, File::RDONLY)
|
87
|
-
file.progress do
|
88
|
-
file.read(100).then do |result|
|
89
|
-
file.close
|
90
|
-
@loop.stop
|
91
|
-
@log = result
|
92
|
-
end
|
93
|
-
end
|
94
|
-
file.catch do |error|
|
95
|
-
@general_failure << error
|
96
|
-
file.close
|
97
|
-
@loop.stop
|
98
|
-
end
|
99
|
-
}
|
100
|
-
|
101
|
-
@general_failure.should == []
|
102
|
-
@log.should == 'write some data to a file'
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should delete a file" do
|
106
|
-
@loop.run { |logger|
|
107
|
-
logger.progress &@logger
|
108
|
-
|
109
|
-
op = @loop.filesystem.unlink(@thefile)
|
110
|
-
op.then do
|
111
|
-
@loop.stop
|
112
|
-
@log = :success
|
113
|
-
end
|
114
|
-
op.catch do |error|
|
115
|
-
@general_failure << error
|
116
|
-
@loop.stop
|
117
|
-
end
|
118
|
-
}
|
119
|
-
|
120
|
-
@general_failure.should == []
|
121
|
-
@log.should == :success
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
1
|
+
require 'libuv'
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
|
5
|
+
describe Libuv::Filesystem do
|
6
|
+
before :each do
|
7
|
+
@log = []
|
8
|
+
@general_failure = []
|
9
|
+
|
10
|
+
@loop = Libuv::Loop.new
|
11
|
+
@filesystem = @loop.filesystem
|
12
|
+
@timeout = @loop.timer do
|
13
|
+
@loop.stop
|
14
|
+
@general_failure << "test timed out"
|
15
|
+
end
|
16
|
+
@timeout.start(4000)
|
17
|
+
|
18
|
+
@logger = proc { |level, errorid, error|
|
19
|
+
begin
|
20
|
+
@general_failure << "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
21
|
+
rescue Exception
|
22
|
+
@general_failure << 'error in logger'
|
23
|
+
end
|
24
|
+
}
|
25
|
+
|
26
|
+
@thefile = "test-file.txt"
|
27
|
+
|
28
|
+
@loop.all(@filesystem, @timeout).catch do |reason|
|
29
|
+
@general_failure << reason.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'directory navigation' do
|
34
|
+
it "should list the contents of a folder" do
|
35
|
+
@loop.run { |logger|
|
36
|
+
logger.progress &@logger
|
37
|
+
|
38
|
+
currentDir = Dir.pwd
|
39
|
+
listing = @filesystem.readdir(currentDir)
|
40
|
+
listing.then do |result|
|
41
|
+
@log = result
|
42
|
+
end
|
43
|
+
listing.catch do |error|
|
44
|
+
@general_failure << error
|
45
|
+
end
|
46
|
+
listing.finally do
|
47
|
+
@loop.stop
|
48
|
+
end
|
49
|
+
}
|
50
|
+
|
51
|
+
@general_failure.should == []
|
52
|
+
(@log.length > 0).should == true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'file manipulation' do
|
57
|
+
it "should create and write to a file" do
|
58
|
+
@loop.run { |logger|
|
59
|
+
logger.progress &@logger
|
60
|
+
|
61
|
+
file = @loop.file(@thefile, File::CREAT|File::WRONLY)
|
62
|
+
file.progress do
|
63
|
+
file.write('write some data to a file').then do
|
64
|
+
file.chmod(777).then do
|
65
|
+
file.close
|
66
|
+
@loop.stop
|
67
|
+
@log = :success
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
file.catch do |error|
|
72
|
+
@general_failure << error
|
73
|
+
file.close
|
74
|
+
@loop.stop
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
78
|
+
@general_failure.should == []
|
79
|
+
@log.should == :success
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should read from a file" do
|
83
|
+
@loop.run { |logger|
|
84
|
+
logger.progress &@logger
|
85
|
+
|
86
|
+
file = @loop.file(@thefile, File::RDONLY)
|
87
|
+
file.progress do
|
88
|
+
file.read(100).then do |result|
|
89
|
+
file.close
|
90
|
+
@loop.stop
|
91
|
+
@log = result
|
92
|
+
end
|
93
|
+
end
|
94
|
+
file.catch do |error|
|
95
|
+
@general_failure << error
|
96
|
+
file.close
|
97
|
+
@loop.stop
|
98
|
+
end
|
99
|
+
}
|
100
|
+
|
101
|
+
@general_failure.should == []
|
102
|
+
@log.should == 'write some data to a file'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should delete a file" do
|
106
|
+
@loop.run { |logger|
|
107
|
+
logger.progress &@logger
|
108
|
+
|
109
|
+
op = @loop.filesystem.unlink(@thefile)
|
110
|
+
op.then do
|
111
|
+
@loop.stop
|
112
|
+
@log = :success
|
113
|
+
end
|
114
|
+
op.catch do |error|
|
115
|
+
@general_failure << error
|
116
|
+
@loop.stop
|
117
|
+
end
|
118
|
+
}
|
119
|
+
|
120
|
+
@general_failure.should == []
|
121
|
+
@log.should == :success
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/idle_spec.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
|
-
require 'libuv'
|
2
|
-
|
3
|
-
|
4
|
-
describe Libuv::Idle do
|
5
|
-
before :each do
|
6
|
-
@log = []
|
7
|
-
@general_failure = []
|
8
|
-
|
9
|
-
@loop = Libuv::Loop.new
|
10
|
-
@server = @loop.pipe
|
11
|
-
@client = @loop.pipe
|
12
|
-
@timeout = @loop.timer do
|
13
|
-
@loop.stop
|
14
|
-
@general_failure << "test timed out"
|
15
|
-
end
|
16
|
-
@timeout.start(5000)
|
17
|
-
|
18
|
-
@loop.all(@server, @client, @timeout).catch do |reason|
|
19
|
-
@general_failure << reason.inspect
|
20
|
-
p "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should increase the idle count when there is nothing to process" do
|
25
|
-
@loop.run { |logger|
|
26
|
-
logger.progress do |level, errorid, error|
|
27
|
-
begin
|
28
|
-
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
29
|
-
rescue Exception
|
30
|
-
p 'error in logger'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
@idle_calls = 0
|
35
|
-
|
36
|
-
idle = @loop.idle do |e|
|
37
|
-
@idle_calls += 1
|
38
|
-
end
|
39
|
-
idle.start
|
40
|
-
|
41
|
-
timer = @loop.timer proc {}
|
42
|
-
timer.start(1, 0)
|
43
|
-
|
44
|
-
stopper = @loop.timer do
|
45
|
-
idle.close
|
46
|
-
timer.close
|
47
|
-
stopper.close
|
48
|
-
@loop.stop
|
49
|
-
end
|
50
|
-
stopper.start(1000, 0)
|
51
|
-
}
|
52
|
-
|
53
|
-
@general_failure.should == []
|
54
|
-
(@idle_calls > 0).should == true
|
55
|
-
end
|
56
|
-
end
|
1
|
+
require 'libuv'
|
2
|
+
|
3
|
+
|
4
|
+
describe Libuv::Idle do
|
5
|
+
before :each do
|
6
|
+
@log = []
|
7
|
+
@general_failure = []
|
8
|
+
|
9
|
+
@loop = Libuv::Loop.new
|
10
|
+
@server = @loop.pipe
|
11
|
+
@client = @loop.pipe
|
12
|
+
@timeout = @loop.timer do
|
13
|
+
@loop.stop
|
14
|
+
@general_failure << "test timed out"
|
15
|
+
end
|
16
|
+
@timeout.start(5000)
|
17
|
+
|
18
|
+
@loop.all(@server, @client, @timeout).catch do |reason|
|
19
|
+
@general_failure << reason.inspect
|
20
|
+
p "Failed with: #{reason.message}\n#{reason.backtrace.join("\n")}\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should increase the idle count when there is nothing to process" do
|
25
|
+
@loop.run { |logger|
|
26
|
+
logger.progress do |level, errorid, error|
|
27
|
+
begin
|
28
|
+
p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
|
29
|
+
rescue Exception
|
30
|
+
p 'error in logger'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@idle_calls = 0
|
35
|
+
|
36
|
+
idle = @loop.idle do |e|
|
37
|
+
@idle_calls += 1
|
38
|
+
end
|
39
|
+
idle.start
|
40
|
+
|
41
|
+
timer = @loop.timer proc {}
|
42
|
+
timer.start(1, 0)
|
43
|
+
|
44
|
+
stopper = @loop.timer do
|
45
|
+
idle.close
|
46
|
+
timer.close
|
47
|
+
stopper.close
|
48
|
+
@loop.stop
|
49
|
+
end
|
50
|
+
stopper.start(1000, 0)
|
51
|
+
}
|
52
|
+
|
53
|
+
@general_failure.should == []
|
54
|
+
(@idle_calls > 0).should == true
|
55
|
+
end
|
56
|
+
end
|