libuv 0.10.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +17 -17
  2. data/.gitmodules +3 -3
  3. data/.rspec +1 -1
  4. data/.travis.yml +16 -16
  5. data/Gemfile +2 -2
  6. data/LICENSE +23 -23
  7. data/README.md +82 -73
  8. data/Rakefile +31 -31
  9. data/lib/libuv.rb +53 -34
  10. data/lib/libuv/async.rb +47 -33
  11. data/lib/libuv/check.rb +55 -48
  12. data/lib/libuv/error.rb +70 -70
  13. data/lib/libuv/ext/ext.rb +264 -256
  14. data/lib/libuv/ext/platform/darwin_x64.rb +12 -12
  15. data/lib/libuv/ext/platform/linux.rb +7 -7
  16. data/lib/libuv/ext/platform/unix.rb +13 -13
  17. data/lib/libuv/ext/platform/windows.rb +26 -26
  18. data/lib/libuv/ext/tasks.rb +27 -27
  19. data/lib/libuv/ext/tasks/mac.rb +23 -23
  20. data/lib/libuv/ext/tasks/unix.rb +23 -23
  21. data/lib/libuv/ext/tasks/win.rb +11 -11
  22. data/lib/libuv/ext/types.rb +234 -229
  23. data/lib/libuv/file.rb +192 -0
  24. data/lib/libuv/filesystem.rb +233 -0
  25. data/lib/libuv/fs_event.rb +31 -31
  26. data/lib/libuv/handle.rb +85 -81
  27. data/lib/libuv/idle.rb +56 -49
  28. data/lib/libuv/loop.rb +338 -310
  29. data/lib/libuv/{assertions.rb → mixins/assertions.rb} +23 -23
  30. data/lib/libuv/mixins/fs_checks.rb +55 -0
  31. data/lib/libuv/{listener.rb → mixins/listener.rb} +34 -34
  32. data/lib/libuv/{net.rb → mixins/net.rb} +37 -37
  33. data/lib/libuv/{resource.rb → mixins/resource.rb} +27 -27
  34. data/lib/libuv/{stream.rb → mixins/stream.rb} +143 -123
  35. data/lib/libuv/pipe.rb +197 -97
  36. data/lib/libuv/prepare.rb +56 -49
  37. data/lib/libuv/q.rb +1 -1
  38. data/lib/libuv/signal.rb +51 -0
  39. data/lib/libuv/tcp.rb +204 -193
  40. data/lib/libuv/timer.rb +88 -75
  41. data/lib/libuv/tty.rb +37 -34
  42. data/lib/libuv/udp.rb +273 -255
  43. data/lib/libuv/version.rb +3 -3
  44. data/lib/libuv/work.rb +63 -61
  45. data/libuv.gemspec +54 -54
  46. data/spec/async_spec.rb +60 -60
  47. data/spec/cpu_spec.rb +10 -0
  48. data/spec/defer_spec.rb +980 -980
  49. data/spec/filesystem_spec.rb +119 -0
  50. data/spec/idle_spec.rb +56 -56
  51. data/spec/pipe_spec.rb +153 -148
  52. data/spec/tcp_spec.rb +203 -188
  53. metadata +73 -49
  54. checksums.yaml +0 -15
  55. data/lib/libuv/simple_async.rb +0 -28
data/spec/tcp_spec.rb CHANGED
@@ -1,188 +1,203 @@
1
- require 'libuv'
2
-
3
-
4
- describe Libuv::TCP do
5
- before :each do
6
- @log = []
7
- @general_failure = []
8
-
9
- @loop = Libuv::Loop.new
10
- @server = @loop.tcp
11
- @client = @loop.tcp
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
- end
21
- end
22
-
23
- describe 'basic client server' do
24
- it "should send a ping and return a pong", :network => true 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
-
35
- @server.bind('127.0.0.1', 34567) do |server|
36
- server.accept do |client|
37
- client.progress do |data|
38
- @log << data
39
-
40
- client.write('pong')
41
- end
42
- client.start_read
43
- end
44
- end
45
-
46
- # catch errors
47
- @server.catch do |reason|
48
- @general_failure << reason.inspect
49
- end
50
-
51
- # start listening
52
- @server.listen(1024)
53
-
54
-
55
-
56
- # connect client to server
57
- @client.connect('127.0.0.1', 34567) do |client|
58
- client.progress do |data|
59
- @log << data
60
-
61
- @client.shutdown
62
- end
63
-
64
- @client.start_read
65
- @client.write('ping')
66
- end
67
-
68
- # catch errors
69
- @client.catch do |reason|
70
- @general_failure << reason.inspect
71
- end
72
-
73
- # close the handle
74
- @client.finally do
75
- @server.close
76
- @loop.stop
77
- end
78
- }
79
-
80
- @general_failure.should == []
81
- @log.should == ['ping', 'pong']
82
- end
83
-
84
- =begin
85
- it "should allow multiple binds to the same address" do
86
- @loop.run { |logger|
87
- logger.progress do |level, errorid, error|
88
- begin
89
- p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
90
- rescue Exception
91
- p 'error in logger'
92
- end
93
- end
94
-
95
-
96
- @server.bind('127.0.0.1', 34567) do |server|
97
- server.accept do |client|
98
- client.progress do |data|
99
- @log << data
100
-
101
- client.write('pong1')
102
- end
103
- client.start_read
104
- end
105
- end
106
-
107
- # catch errors
108
- @server.catch do |reason|
109
- @general_failure << reason.inspect
110
- end
111
-
112
- # start listening
113
- @server.listen(1024)
114
-
115
-
116
- @server2 = @loop.tcp
117
-
118
- @server2.bind('127.0.0.1', 34567) do |server|
119
- server.accept do |client|
120
- client.progress do |data|
121
- @log << data
122
-
123
- client.write('pong2')
124
- end
125
- client.start_read
126
- end
127
- end
128
-
129
- # catch errors
130
- @server2.catch do |reason|
131
- @general_failure << reason.inspect
132
- end
133
-
134
- # start listening
135
- @server2.listen(1024)
136
-
137
-
138
- # connect client to server
139
- @client.connect('127.0.0.1', 34567) do |client|
140
- client.progress do |data|
141
- @log << data
142
-
143
- @client.shutdown
144
- end
145
-
146
- @client.start_read
147
- @client.write('ping1')
148
- end
149
-
150
- # catch errors
151
- @client.catch do |reason|
152
- @general_failure << reason.inspect
153
- end
154
-
155
- # close the handle
156
- @client.finally do
157
- @server.close
158
- @loop.stop
159
- end
160
-
161
- @client2 = @loop.tcp
162
-
163
- # connect client to server
164
- @client2.connect('127.0.0.1', 34567) do |client|
165
- client.progress do |data|
166
- @log << data
167
-
168
- @client.shutdown
169
- end
170
-
171
- @client2.start_read
172
- @client2.write('ping2')
173
- end
174
-
175
- # catch errors
176
- @client2.catch do |reason|
177
- @general_failure << reason.inspect
178
- end
179
-
180
- }
181
-
182
- @general_failure.should == []
183
- @log.should == ['ping', 'pong']
184
- end
185
- =end
186
-
187
- end
188
- end
1
+ require 'libuv'
2
+ require 'thread'
3
+
4
+
5
+ describe Libuv::TCP do
6
+ before :each do
7
+ @log = []
8
+ @general_failure = []
9
+
10
+ @loop = Libuv::Loop.new
11
+ @server = @loop.tcp
12
+ @client = @loop.tcp
13
+ @timeout = @loop.timer do
14
+ @loop.stop
15
+ @loop2.stop if @loop2
16
+ @general_failure << "test timed out"
17
+ end
18
+ @timeout.start(5000)
19
+
20
+ @loop.all(@server, @client, @timeout).catch do |reason|
21
+ @general_failure << reason.inspect
22
+ end
23
+
24
+
25
+ @pipefile = "/tmp/test-pipe.pipe"
26
+
27
+ begin
28
+ File.unlink(@pipefile)
29
+ rescue
30
+ end
31
+ end
32
+
33
+ describe 'basic client server' do
34
+ it "should send a ping and return a pong", :network => true do
35
+ @loop.run { |logger|
36
+ logger.progress do |level, errorid, error|
37
+ begin
38
+ p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
39
+ rescue Exception
40
+ p 'error in logger'
41
+ end
42
+ end
43
+
44
+
45
+ @server.bind('127.0.0.1', 34567) do |server|
46
+ server.accept do |client|
47
+ client.progress do |data|
48
+ @log << data
49
+
50
+ client.write('pong')
51
+ end
52
+ client.start_read
53
+ end
54
+ end
55
+
56
+ # catch errors
57
+ @server.catch do |reason|
58
+ @general_failure << reason.inspect
59
+ end
60
+
61
+ # start listening
62
+ @server.listen(1024)
63
+
64
+
65
+
66
+ # connect client to server
67
+ @client.connect('127.0.0.1', 34567) do |client|
68
+ client.progress do |data|
69
+ @log << data
70
+
71
+ @client.shutdown
72
+ end
73
+
74
+ @client.start_read
75
+ @client.write('ping')
76
+ end
77
+
78
+ # catch errors
79
+ @client.catch do |reason|
80
+ @general_failure << reason.inspect
81
+ end
82
+
83
+ # close the handle
84
+ @client.finally do
85
+ @server.close
86
+ @loop.stop
87
+ end
88
+ }
89
+
90
+ @general_failure.should == []
91
+ @log.should == ['ping', 'pong']
92
+ end
93
+ end
94
+
95
+ it "should handle requests on different threads", :network => true do
96
+ @sync = Mutex.new
97
+
98
+ @loop.run { |logger|
99
+ logger.progress do |level, errorid, error|
100
+ begin
101
+ p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
102
+ rescue Exception
103
+ p 'error in logger'
104
+ end
105
+ end
106
+
107
+
108
+ @remote = nil
109
+ @server.bind('127.0.0.1', 45678) do |server|
110
+ server.accept do |client|
111
+ @remote.write2(client)
112
+ end
113
+ end
114
+
115
+ # catch errors
116
+ @server.catch do |reason|
117
+ @general_failure << reason.inspect
118
+ end
119
+
120
+
121
+ @pipeserve = @loop.pipe(true)
122
+ @pipeserve.bind(@pipefile) do |connection|
123
+ connection.accept do |client|
124
+ @remote = client
125
+
126
+ # start listening on TCP server
127
+ @server.listen(1024)
128
+
129
+ # connect client to server
130
+ @client.connect('127.0.0.1', 45678) do |client|
131
+ client.progress do |data|
132
+ @sync.synchronize {
133
+ @log << data
134
+ }
135
+ @client.shutdown
136
+ end
137
+
138
+ @client.start_read
139
+ @client.write('ping')
140
+ end
141
+ end
142
+ end
143
+
144
+ # start listening
145
+ @pipeserve.listen(1024)
146
+
147
+
148
+
149
+ # catch errors
150
+ @client.catch do |reason|
151
+ @general_failure << reason.inspect
152
+ end
153
+
154
+ # close the handle
155
+ @client.finally do
156
+ @server.close
157
+ @pipeserve.close
158
+ end
159
+
160
+
161
+
162
+ Thread.new do
163
+ @loop2 = Libuv::Loop.new
164
+ @pipeclient = @loop2.pipe(true)
165
+
166
+
167
+ @loop2.run do |logger|
168
+ logger.progress do |level, errorid, error|
169
+ begin
170
+ p "Log called: #{level}: #{errorid}\n#{error.message}\n#{error.backtrace.join("\n")}\n"
171
+ rescue Exception
172
+ p 'error in logger'
173
+ end
174
+ end
175
+
176
+ # connect client to server
177
+ @pipeclient.connect(@pipefile) do |client|
178
+ @pipeclient.progress do |data, connection|
179
+ connection.progress do |data|
180
+ @sync.synchronize {
181
+ @log << data
182
+ }
183
+ connection.write('pong')
184
+ end
185
+ connection.start_read
186
+ connection.finally do
187
+ @pipeclient.close
188
+ @loop2.stop
189
+ @loop.stop
190
+ end
191
+ end
192
+
193
+ @pipeclient.start_read2
194
+ end
195
+ end
196
+ end
197
+ }
198
+
199
+ @general_failure.should == []
200
+ @log.should == ['ping', 'pong']
201
+ end
202
+
203
+ end
metadata CHANGED
@@ -1,86 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libuv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ prerelease:
5
+ version: 0.10.2
5
6
  platform: ruby
6
7
  authors:
7
8
  - Bulat Shakirzyanov
8
9
  - Stephen von Takach
9
- autorequire:
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-08-23 00:00:00.000000000 Z
13
+ date: 2013-09-03 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: ffi
16
- requirement: !ruby/object:Gem::Requirement
17
+ version_requirements: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - ! '>='
19
+ - - '>='
19
20
  - !ruby/object:Gem::Version
20
21
  version: '1.9'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.9'
28
+ none: false
29
+ prerelease: false
30
+ type: :runtime
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: thread_safe
30
- requirement: !ruby/object:Gem::Requirement
33
+ version_requirements: !ruby/object:Gem::Requirement
31
34
  requirements:
32
- - - ! '>='
35
+ - - '>='
33
36
  - !ruby/object:Gem::Version
34
37
  version: '0'
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirement: !ruby/object:Gem::Requirement
38
40
  requirements:
39
- - - ! '>='
41
+ - - '>='
40
42
  - !ruby/object:Gem::Version
41
43
  version: '0'
44
+ none: false
45
+ prerelease: false
46
+ type: :runtime
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: rspec
44
- requirement: !ruby/object:Gem::Requirement
49
+ version_requirements: !ruby/object:Gem::Requirement
45
50
  requirements:
46
- - - ! '>='
51
+ - - '>='
47
52
  - !ruby/object:Gem::Version
48
53
  version: '2.14'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirement: !ruby/object:Gem::Requirement
52
56
  requirements:
53
- - - ! '>='
57
+ - - '>='
54
58
  - !ruby/object:Gem::Version
55
59
  version: '2.14'
60
+ none: false
61
+ prerelease: false
62
+ type: :development
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: rake
58
- requirement: !ruby/object:Gem::Requirement
65
+ version_requirements: !ruby/object:Gem::Requirement
59
66
  requirements:
60
- - - ! '>='
67
+ - - '>='
61
68
  - !ruby/object:Gem::Version
62
69
  version: '10.1'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirement: !ruby/object:Gem::Requirement
66
72
  requirements:
67
- - - ! '>='
73
+ - - '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '10.1'
76
+ none: false
77
+ prerelease: false
78
+ type: :development
70
79
  - !ruby/object:Gem::Dependency
71
80
  name: yard
72
- requirement: !ruby/object:Gem::Requirement
81
+ version_requirements: !ruby/object:Gem::Requirement
73
82
  requirements:
74
- - - ! '>='
83
+ - - '>='
75
84
  - !ruby/object:Gem::Version
76
85
  version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirement: !ruby/object:Gem::Requirement
80
88
  requirements:
81
- - - ! '>='
89
+ - - '>='
82
90
  - !ruby/object:Gem::Version
83
91
  version: '0'
92
+ none: false
93
+ prerelease: false
94
+ type: :development
84
95
  description: An opinionated wrapper around libuv for Ruby
85
96
  email:
86
97
  - mallluhuct@gmail.com
@@ -101,7 +112,6 @@ files:
101
112
  - ext/README.md
102
113
  - ext/Rakefile
103
114
  - lib/libuv.rb
104
- - lib/libuv/assertions.rb
105
115
  - lib/libuv/async.rb
106
116
  - lib/libuv/check.rb
107
117
  - lib/libuv/error.rb
@@ -115,18 +125,22 @@ files:
115
125
  - lib/libuv/ext/tasks/unix.rb
116
126
  - lib/libuv/ext/tasks/win.rb
117
127
  - lib/libuv/ext/types.rb
128
+ - lib/libuv/file.rb
129
+ - lib/libuv/filesystem.rb
118
130
  - lib/libuv/fs_event.rb
119
131
  - lib/libuv/handle.rb
120
132
  - lib/libuv/idle.rb
121
- - lib/libuv/listener.rb
122
133
  - lib/libuv/loop.rb
123
- - lib/libuv/net.rb
134
+ - lib/libuv/mixins/assertions.rb
135
+ - lib/libuv/mixins/fs_checks.rb
136
+ - lib/libuv/mixins/listener.rb
137
+ - lib/libuv/mixins/net.rb
138
+ - lib/libuv/mixins/resource.rb
139
+ - lib/libuv/mixins/stream.rb
124
140
  - lib/libuv/pipe.rb
125
141
  - lib/libuv/prepare.rb
126
142
  - lib/libuv/q.rb
127
- - lib/libuv/resource.rb
128
- - lib/libuv/simple_async.rb
129
- - lib/libuv/stream.rb
143
+ - lib/libuv/signal.rb
130
144
  - lib/libuv/tcp.rb
131
145
  - lib/libuv/timer.rb
132
146
  - lib/libuv/tty.rb
@@ -135,7 +149,9 @@ files:
135
149
  - lib/libuv/work.rb
136
150
  - libuv.gemspec
137
151
  - spec/async_spec.rb
152
+ - spec/cpu_spec.rb
138
153
  - spec/defer_spec.rb
154
+ - spec/filesystem_spec.rb
139
155
  - spec/idle_spec.rb
140
156
  - spec/pipe_spec.rb
141
157
  - spec/tcp_spec.rb
@@ -357,26 +373,34 @@ files:
357
373
  homepage: https://github.com/cotag/libuv
358
374
  licenses:
359
375
  - MIT
360
- metadata: {}
361
- post_install_message:
376
+ post_install_message:
362
377
  rdoc_options: []
363
378
  require_paths:
364
379
  - lib
365
380
  required_ruby_version: !ruby/object:Gem::Requirement
366
381
  requirements:
367
- - - ! '>='
382
+ - - '>='
368
383
  - !ruby/object:Gem::Version
369
384
  version: 1.9.2
385
+ none: false
370
386
  required_rubygems_version: !ruby/object:Gem::Requirement
371
387
  requirements:
372
- - - ! '>='
388
+ - - '>='
373
389
  - !ruby/object:Gem::Version
374
390
  version: '0'
391
+ none: false
375
392
  requirements: []
376
- rubyforge_project:
377
- rubygems_version: 2.0.7
378
- signing_key:
379
- specification_version: 4
393
+ rubyforge_project:
394
+ rubygems_version: 1.8.24
395
+ signing_key:
396
+ specification_version: 3
380
397
  summary: libuv bindings for Ruby
381
- test_files: []
382
- has_rdoc:
398
+ test_files:
399
+ - spec/async_spec.rb
400
+ - spec/cpu_spec.rb
401
+ - spec/defer_spec.rb
402
+ - spec/filesystem_spec.rb
403
+ - spec/idle_spec.rb
404
+ - spec/pipe_spec.rb
405
+ - spec/tcp_spec.rb
406
+ has_rdoc: