libuv 0.11.22 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +19 -17
  3. data/.gitmodules +3 -3
  4. data/.rspec +1 -1
  5. data/.travis.yml +16 -16
  6. data/Gemfile +4 -4
  7. data/LICENSE +23 -23
  8. data/README.md +89 -89
  9. data/Rakefile +31 -31
  10. data/lib/libuv.rb +54 -54
  11. data/lib/libuv/async.rb +47 -47
  12. data/lib/libuv/check.rb +55 -55
  13. data/lib/libuv/dns.rb +85 -85
  14. data/lib/libuv/error.rb +78 -74
  15. data/lib/libuv/ext/ext.rb +260 -258
  16. data/lib/libuv/ext/platform/darwin_x64.rb +23 -23
  17. data/lib/libuv/ext/platform/linux.rb +7 -7
  18. data/lib/libuv/ext/platform/unix.rb +29 -29
  19. data/lib/libuv/ext/platform/windows.rb +40 -40
  20. data/lib/libuv/ext/tasks.rb +31 -31
  21. data/lib/libuv/ext/tasks/mac.rb +23 -23
  22. data/lib/libuv/ext/tasks/unix.rb +23 -23
  23. data/lib/libuv/ext/tasks/win.rb +14 -14
  24. data/lib/libuv/ext/types.rb +238 -238
  25. data/lib/libuv/file.rb +281 -269
  26. data/lib/libuv/filesystem.rb +232 -232
  27. data/lib/libuv/fs_event.rb +31 -31
  28. data/lib/libuv/handle.rb +85 -85
  29. data/lib/libuv/idle.rb +56 -56
  30. data/lib/libuv/loop.rb +412 -412
  31. data/lib/libuv/mixins/assertions.rb +23 -23
  32. data/lib/libuv/mixins/fs_checks.rb +60 -58
  33. data/lib/libuv/mixins/listener.rb +34 -34
  34. data/lib/libuv/mixins/net.rb +40 -40
  35. data/lib/libuv/mixins/resource.rb +27 -27
  36. data/lib/libuv/mixins/stream.rb +153 -154
  37. data/lib/libuv/pipe.rb +184 -203
  38. data/lib/libuv/prepare.rb +56 -56
  39. data/lib/libuv/signal.rb +51 -51
  40. data/lib/libuv/tcp.rb +334 -334
  41. data/lib/libuv/timer.rb +85 -85
  42. data/lib/libuv/tty.rb +37 -37
  43. data/lib/libuv/udp.rb +240 -240
  44. data/lib/libuv/version.rb +3 -3
  45. data/lib/libuv/work.rb +75 -75
  46. data/libuv.gemspec +56 -56
  47. data/spec/async_spec.rb +61 -60
  48. data/spec/cpu_spec.rb +10 -10
  49. data/spec/defer_spec.rb +980 -980
  50. data/spec/dns_spec.rb +96 -90
  51. data/spec/filesystem_spec.rb +270 -261
  52. data/spec/idle_spec.rb +56 -56
  53. data/spec/pipe_spec.rb +160 -160
  54. data/spec/tcp_spec.rb +271 -267
  55. metadata +64 -51
data/spec/dns_spec.rb CHANGED
@@ -1,90 +1,96 @@
1
- require 'libuv'
2
-
3
-
4
- describe Libuv::Dns do
5
- before :each do
6
- @log = []
7
- @general_failure = []
8
-
9
- @loop = Libuv::Loop.default
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
- expect(@general_failure).to eq([])
42
- expect(@result).to eq('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
- expect(@general_failure).to eq([])
65
- expect(@result).to eq('::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
- expect(@general_failure).to eq([])
88
- expect(@result).to eq('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.default
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
+ @timeout.close
35
+ @loop.stop
36
+ }, proc { |err|
37
+ @general_failure << err
38
+ @timeout.close
39
+ @loop.stop
40
+ }
41
+ }
42
+
43
+ expect(@general_failure).to eq([])
44
+ expect(@result).to eq('127.0.0.1')
45
+ end
46
+
47
+ it "should resolve localhost using IP6", :network => true do
48
+ @loop.run { |logger|
49
+ logger.progress do |level, errorid, error|
50
+ begin
51
+ p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
52
+ rescue Exception
53
+ p 'error in logger'
54
+ end
55
+ end
56
+
57
+ @loop.lookup('localhost', :IPv6).then proc { |addrinfo|
58
+ @result = addrinfo[0][0]
59
+ @timeout.close
60
+ @loop.stop
61
+ }, proc { |err|
62
+ @general_failure << err
63
+ @timeout.close
64
+ @loop.stop
65
+ }
66
+ }
67
+
68
+ expect(@general_failure).to eq([])
69
+ expect(@result).to eq('::1')
70
+ end
71
+
72
+ it "should resolve loop back" do
73
+ @loop.run { |logger|
74
+ logger.progress do |level, errorid, error|
75
+ begin
76
+ p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
77
+ rescue Exception
78
+ p 'error in logger'
79
+ end
80
+ end
81
+
82
+ @loop.lookup('127.0.0.1').then proc { |addrinfo|
83
+ @result = addrinfo[0][0]
84
+ @timeout.close
85
+ @loop.stop
86
+ }, proc { |err|
87
+ @general_failure << err
88
+ @timeout.close
89
+ @loop.stop
90
+ }
91
+ }
92
+
93
+ expect(@general_failure).to eq([])
94
+ expect(@result).to eq('127.0.0.1')
95
+ end
96
+ end
@@ -1,261 +1,270 @@
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.default
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
- expect(@general_failure).to eq([])
52
- expect((@log.length > 0)).to eq(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
- expect(@general_failure).to eq([])
79
- expect(@log).to eq(: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
- expect(@general_failure).to eq([])
102
- expect(@log).to eq('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
- expect(@general_failure).to eq([])
121
- expect(@log).to eq(:success)
122
- end
123
- end
124
-
125
- describe 'file streaming' do
126
- it "should send a file over a stream", :network => true do
127
- @loop.run { |logger|
128
- logger.progress &@logger
129
-
130
- @server = @loop.tcp
131
- @client = @loop.tcp
132
-
133
- @server.bind('127.0.0.1', 34570) do |server|
134
- server.accept do |client|
135
- client.progress do |data|
136
- file = @loop.file('.rspec', File::RDONLY)
137
- file.progress do
138
- file.send_file(client).then(proc {
139
- file.close
140
- client.close
141
- }, proc { |error|
142
- @general_failure << error
143
- })
144
- end
145
- file.catch do |error|
146
- @general_failure << error.inspect
147
- file.close
148
- client.close
149
- end
150
- end
151
- client.start_read
152
- client.finally do
153
- @server.close
154
- @loop.stop
155
- end
156
- end
157
- end
158
- # catch errors
159
- @server.catch do |reason|
160
- @general_failure << reason.inspect
161
- @loop.stop
162
- end
163
- # start listening
164
- @server.listen(5)
165
-
166
-
167
- # connect client to server
168
- @client.connect('127.0.0.1', 34570) do |client|
169
- client.progress do |data|
170
- @log << data
171
- end
172
-
173
- @client.start_read
174
- @client.write('send file')
175
- end
176
- # catch errors
177
- @client.catch do |reason|
178
- @general_failure << reason.inspect
179
- @server.close
180
- @loop.stop
181
- end
182
- }
183
-
184
- expect(@general_failure).to eq([])
185
- # Windows GIT adds the carriage return
186
- if FFI::Platform.windows?
187
- expect(@log).to eq(["--format progress\r\n"])
188
- else
189
- expect(@log).to eq(["--format progress\n"])
190
- end
191
- end
192
-
193
- it "should send a file as a HTTP chunked response", :network => true do
194
- @loop.run { |logger|
195
- logger.progress &@logger
196
-
197
- @server = @loop.tcp
198
- @client = @loop.tcp
199
-
200
- @server.bind('127.0.0.1', 34568) do |server|
201
- server.accept do |client|
202
- client.progress do |data|
203
- file = @loop.file('.rspec', File::RDONLY)
204
- file.progress do
205
- file.send_file(client, :http).then(proc {
206
- file.close
207
- client.close
208
- }, proc { |error|
209
- @general_failure << error
210
- })
211
- end
212
- file.catch do |error|
213
- @general_failure << error.inspect
214
- file.close
215
- client.close
216
- end
217
- end
218
- client.start_read
219
- client.finally do
220
- @server.close
221
- @loop.stop
222
- end
223
- end
224
- end
225
- # catch errors
226
- @server.catch do |reason|
227
- @general_failure << reason.inspect
228
- @loop.stop
229
- end
230
- # start listening
231
- @server.listen(5)
232
-
233
-
234
- # connect client to server
235
- @client.connect('127.0.0.1', 34568) do |client|
236
- client.progress do |data|
237
- @log << data
238
- end
239
-
240
- @client.start_read
241
- @client.write('send file')
242
- end
243
- # catch errors
244
- @client.catch do |reason|
245
- @general_failure << reason.inspect
246
- @server.close
247
- @loop.stop
248
- end
249
- }
250
-
251
- expect(@general_failure).to eq([])
252
-
253
- # Windows GIT adds the carriage return
254
- if FFI::Platform.windows?
255
- expect(@log.join('')).to eq("13\r\n--format progress\r\n\r\n0\r\n\r\n")
256
- else
257
- expect(@log.join('')).to eq("12\r\n--format progress\n\r\n0\r\n\r\n")
258
- end
259
- end
260
- end
261
- 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.default
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
+ @timeout.close
48
+ @loop.stop
49
+ end
50
+ }
51
+
52
+ expect(@general_failure).to eq([])
53
+ expect((@log.length > 0)).to eq(true)
54
+ end
55
+ end
56
+
57
+ describe 'file manipulation' do
58
+ it "should create and write to a file" do
59
+ @loop.run { |logger|
60
+ logger.progress &@logger
61
+
62
+ file = @loop.file(@thefile, File::CREAT|File::WRONLY)
63
+ file.progress do
64
+ file.write('write some data to a file').then do
65
+ file.chmod(777).then do
66
+ file.close
67
+ @timeout.close
68
+ @loop.stop
69
+ @log = :success
70
+ end
71
+ end
72
+ end
73
+ file.catch do |error|
74
+ @general_failure << error
75
+ @timeout.close
76
+ file.close
77
+ @loop.stop
78
+ end
79
+ }
80
+
81
+ expect(@general_failure).to eq([])
82
+ expect(@log).to eq(:success)
83
+ end
84
+
85
+ it "should read from a file" do
86
+ @loop.run { |logger|
87
+ logger.progress &@logger
88
+
89
+ file = @loop.file(@thefile, File::RDONLY)
90
+ file.progress do
91
+ file.read(100).then do |result|
92
+ file.close
93
+ @timeout.close
94
+ @loop.stop
95
+ @log = result
96
+ end
97
+ end
98
+ file.catch do |error|
99
+ @general_failure << error
100
+ @timeout.close
101
+ file.close
102
+ @loop.stop
103
+ end
104
+ }
105
+
106
+ expect(@general_failure).to eq([])
107
+ expect(@log).to eq('write some data to a file')
108
+ end
109
+
110
+ it "should delete a file" do
111
+ @loop.run { |logger|
112
+ logger.progress &@logger
113
+
114
+ op = @loop.filesystem.unlink(@thefile)
115
+ op.then do
116
+ @timeout.close
117
+ @loop.stop
118
+ @log = :success
119
+ end
120
+ op.catch do |error|
121
+ @general_failure << error
122
+ @timeout.close
123
+ @loop.stop
124
+ end
125
+ }
126
+
127
+ expect(@general_failure).to eq([])
128
+ expect(@log).to eq(:success)
129
+ end
130
+ end
131
+
132
+ describe 'file streaming' do
133
+ it "should send a file over a stream", :network => true do
134
+ @loop.run { |logger|
135
+ logger.progress &@logger
136
+
137
+ @server = @loop.tcp
138
+ @client = @loop.tcp
139
+
140
+ @server.bind('127.0.0.1', 34570) do |server|
141
+ server.accept do |client|
142
+ client.progress do |data|
143
+ file = @loop.file('.rspec', File::RDONLY)
144
+ file.progress do
145
+ file.send_file(client).then(proc {
146
+ file.close
147
+ client.close
148
+ }, proc { |error|
149
+ @general_failure << error
150
+ })
151
+ end
152
+ file.catch do |error|
153
+ @general_failure << error.inspect
154
+ file.close
155
+ client.close
156
+ end
157
+ end
158
+ client.start_read
159
+ client.finally do
160
+ @timeout.close
161
+ @server.close
162
+ @loop.stop
163
+ end
164
+ end
165
+ end
166
+ # catch errors
167
+ @server.catch do |reason|
168
+ @general_failure << reason.inspect
169
+ @loop.stop
170
+ end
171
+ # start listening
172
+ @server.listen(5)
173
+
174
+
175
+ # connect client to server
176
+ @client.connect('127.0.0.1', 34570) do |client|
177
+ client.progress do |data|
178
+ @log << data
179
+ end
180
+
181
+ @client.start_read
182
+ @client.write('send file')
183
+ end
184
+ # catch errors
185
+ @client.catch do |reason|
186
+ @general_failure << reason.inspect
187
+ @server.close
188
+ @loop.stop
189
+ end
190
+ }
191
+
192
+ expect(@general_failure).to eq([])
193
+ # Windows GIT adds the carriage return
194
+ if FFI::Platform.windows?
195
+ expect(@log).to eq(["--format progress\r\n"])
196
+ else
197
+ expect(@log).to eq(["--format progress\n"])
198
+ end
199
+ end
200
+
201
+ it "should send a file as a HTTP chunked response", :network => true do
202
+ @loop.run { |logger|
203
+ logger.progress &@logger
204
+
205
+ @server = @loop.tcp
206
+ @client = @loop.tcp
207
+
208
+ @server.bind('127.0.0.1', 34568) do |server|
209
+ server.accept do |client|
210
+ client.progress do |data|
211
+ file = @loop.file('.rspec', File::RDONLY)
212
+ file.progress do
213
+ file.send_file(client, :http).then(proc {
214
+ file.close
215
+ client.close
216
+ }, proc { |error|
217
+ @general_failure << error
218
+ })
219
+ end
220
+ file.catch do |error|
221
+ @general_failure << error.inspect
222
+ file.close
223
+ client.close
224
+ end
225
+ end
226
+ client.start_read
227
+ client.finally do
228
+ @timeout.close
229
+ @server.close
230
+ @loop.stop
231
+ end
232
+ end
233
+ end
234
+ # catch errors
235
+ @server.catch do |reason|
236
+ @general_failure << reason.inspect
237
+ @loop.stop
238
+ end
239
+ # start listening
240
+ @server.listen(5)
241
+
242
+
243
+ # connect client to server
244
+ @client.connect('127.0.0.1', 34568) do |client|
245
+ client.progress do |data|
246
+ @log << data
247
+ end
248
+
249
+ @client.start_read
250
+ @client.write('send file')
251
+ end
252
+ # catch errors
253
+ @client.catch do |reason|
254
+ @general_failure << reason.inspect
255
+ @server.close
256
+ @loop.stop
257
+ end
258
+ }
259
+
260
+ expect(@general_failure).to eq([])
261
+
262
+ # Windows GIT adds the carriage return
263
+ if FFI::Platform.windows?
264
+ expect(@log.join('')).to eq("13\r\n--format progress\r\n\r\n0\r\n\r\n")
265
+ else
266
+ expect(@log.join('')).to eq("12\r\n--format progress\n\r\n0\r\n\r\n")
267
+ end
268
+ end
269
+ end
270
+ end