libuv 0.11.21 → 0.11.22

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 +17 -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 -88
  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 +74 -73
  15. data/lib/libuv/ext/ext.rb +258 -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 +269 -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 +58 -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 +154 -154
  37. data/lib/libuv/pipe.rb +203 -203
  38. data/lib/libuv/prepare.rb +56 -56
  39. data/lib/libuv/signal.rb +51 -51
  40. data/lib/libuv/tcp.rb +334 -332
  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 +60 -60
  48. data/spec/cpu_spec.rb +10 -10
  49. data/spec/defer_spec.rb +980 -980
  50. data/spec/dns_spec.rb +90 -90
  51. data/spec/filesystem_spec.rb +261 -250
  52. data/spec/idle_spec.rb +56 -56
  53. data/spec/pipe_spec.rb +160 -160
  54. data/spec/tcp_spec.rb +267 -267
  55. metadata +55 -61
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.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
+ @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,250 +1,261 @@
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
- expect(@log).to eq(["--format progress\n"])
186
- end
187
-
188
- it "should send a file as a HTTP chunked response", :network => true do
189
- @loop.run { |logger|
190
- logger.progress &@logger
191
-
192
- @server = @loop.tcp
193
- @client = @loop.tcp
194
-
195
- @server.bind('127.0.0.1', 34568) do |server|
196
- server.accept do |client|
197
- client.progress do |data|
198
- file = @loop.file('.rspec', File::RDONLY)
199
- file.progress do
200
- file.send_file(client, :http).then(proc {
201
- file.close
202
- client.close
203
- }, proc { |error|
204
- @general_failure << error
205
- })
206
- end
207
- file.catch do |error|
208
- @general_failure << error.inspect
209
- file.close
210
- client.close
211
- end
212
- end
213
- client.start_read
214
- client.finally do
215
- @server.close
216
- @loop.stop
217
- end
218
- end
219
- end
220
- # catch errors
221
- @server.catch do |reason|
222
- @general_failure << reason.inspect
223
- @loop.stop
224
- end
225
- # start listening
226
- @server.listen(5)
227
-
228
-
229
- # connect client to server
230
- @client.connect('127.0.0.1', 34568) do |client|
231
- client.progress do |data|
232
- @log << data
233
- end
234
-
235
- @client.start_read
236
- @client.write('send file')
237
- end
238
- # catch errors
239
- @client.catch do |reason|
240
- @general_failure << reason.inspect
241
- @server.close
242
- @loop.stop
243
- end
244
- }
245
-
246
- expect(@general_failure).to eq([])
247
- expect(@log).to eq(["12\r\n--format progress\n\r\n", "0\r\n\r\n"])
248
- end
249
- end
250
- 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
+ @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