uvrb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/.gitignore +17 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +13 -0
  5. data/Formula/libuv.rb +20 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +24 -0
  8. data/README.rdoc +70 -0
  9. data/Rakefile +29 -0
  10. data/examples/example +0 -0
  11. data/examples/example.c +37 -0
  12. data/examples/example.rb +29 -0
  13. data/examples/example_oop.rb +26 -0
  14. data/examples/python.py +1 -0
  15. data/examples/ruby.rb +1 -0
  16. data/examples/tcp_client_oop.rb +31 -0
  17. data/examples/tcp_example +0 -0
  18. data/examples/tcp_example.c +68 -0
  19. data/examples/tcp_example.rb +41 -0
  20. data/examples/tcp_example_oop.rb +43 -0
  21. data/examples/tcp_example_plain.rb +19 -0
  22. data/examples/tty_example.rb +20 -0
  23. data/features/async.feature +38 -0
  24. data/features/idle.feature +44 -0
  25. data/features/pipe.feature +150 -0
  26. data/features/prepare_and_check.feature +49 -0
  27. data/features/step_definitions/additional_cli_steps.rb +20 -0
  28. data/features/support/env.rb +6 -0
  29. data/lib/uv.rb +248 -0
  30. data/lib/uv/assertions.rb +24 -0
  31. data/lib/uv/async.rb +24 -0
  32. data/lib/uv/check.rb +27 -0
  33. data/lib/uv/error.rb +58 -0
  34. data/lib/uv/file.rb +221 -0
  35. data/lib/uv/file/stat.rb +35 -0
  36. data/lib/uv/filesystem.rb +335 -0
  37. data/lib/uv/fs_event.rb +21 -0
  38. data/lib/uv/handle.rb +65 -0
  39. data/lib/uv/idle.rb +27 -0
  40. data/lib/uv/listener.rb +26 -0
  41. data/lib/uv/loop.rb +326 -0
  42. data/lib/uv/net.rb +31 -0
  43. data/lib/uv/pipe.rb +47 -0
  44. data/lib/uv/prepare.rb +27 -0
  45. data/lib/uv/resource.rb +20 -0
  46. data/lib/uv/stream.rb +105 -0
  47. data/lib/uv/tasks.rb +27 -0
  48. data/lib/uv/tasks/mac.rb +23 -0
  49. data/lib/uv/tasks/unix.rb +23 -0
  50. data/lib/uv/tasks/win.rb +2 -0
  51. data/lib/uv/tcp.rb +162 -0
  52. data/lib/uv/timer.rb +48 -0
  53. data/lib/uv/tty.rb +30 -0
  54. data/lib/uv/types.rb +249 -0
  55. data/lib/uv/types/darwin_x64.rb +10 -0
  56. data/lib/uv/types/linux.rb +6 -0
  57. data/lib/uv/types/unix.rb +12 -0
  58. data/lib/uv/types/windows.rb +13 -0
  59. data/lib/uv/udp.rb +215 -0
  60. data/lib/uv/version.rb +3 -0
  61. data/lib/uvrb.rb +1 -0
  62. data/spec/shared_examples/handle.rb +54 -0
  63. data/spec/shared_examples/stream.rb +109 -0
  64. data/spec/spec_helper.rb +26 -0
  65. data/spec/uv/async_spec.rb +18 -0
  66. data/spec/uv/check_spec.rb +30 -0
  67. data/spec/uv/file_spec.rb +177 -0
  68. data/spec/uv/filesystem_spec.rb +246 -0
  69. data/spec/uv/fs_event_spec.rb +10 -0
  70. data/spec/uv/idle_spec.rb +30 -0
  71. data/spec/uv/loop_spec.rb +241 -0
  72. data/spec/uv/pipe_spec.rb +54 -0
  73. data/spec/uv/prepare_spec.rb +30 -0
  74. data/spec/uv/tcp_spec.rb +134 -0
  75. data/spec/uv/timer_spec.rb +61 -0
  76. data/spec/uv/tty_spec.rb +53 -0
  77. data/spec/uv/udp_spec.rb +190 -0
  78. data/uvrb.gemspec +28 -0
  79. metadata +247 -0
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::FSEvent do
4
+ let(:handle_name) { :fs_event }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::FSEvent.new(loop, pointer) { |e, filename, type| } }
8
+
9
+ it_behaves_like 'a handle'
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Idle do
4
+ let(:handle_name) { :idle }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::Idle.new(loop, pointer) }
8
+
9
+ it_behaves_like 'a handle'
10
+
11
+ describe "#start" do
12
+ it "requires a block" do
13
+ expect { subject.start }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it "calls UV.idle_start" do
17
+ UV.should_receive(:idle_start).with(pointer, subject.method(:on_idle))
18
+
19
+ subject.start { |e| }
20
+ end
21
+ end
22
+
23
+ describe "#stop" do
24
+ it "calls UV.idle_stop" do
25
+ UV.should_receive(:idle_stop).with(pointer)
26
+
27
+ subject.stop
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,241 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Loop do
4
+ let(:loop_pointer) { double() }
5
+
6
+ describe ".default" do
7
+ it "calls UV.loop_default internally" do
8
+ UV.should_receive(:default_loop).once.and_return(loop_pointer)
9
+ FFI::AutoPointer.should_receive(:new).once.with(loop_pointer, UV.method(:loop_delete))
10
+ UV::Loop.default
11
+ end
12
+ end
13
+
14
+ describe ".new" do
15
+ it "calls UV.loop_new" do
16
+ UV.should_receive(:loop_new).once.and_return(loop_pointer)
17
+ FFI::AutoPointer.should_receive(:new).once.with(loop_pointer, UV.method(:loop_delete))
18
+ UV::Loop.new
19
+ end
20
+ end
21
+
22
+ subject do
23
+ FFI::AutoPointer.should_receive(:new).once.with(loop_pointer, UV.method(:loop_delete)).and_return(loop_pointer)
24
+ UV::Loop.create(loop_pointer)
25
+ end
26
+
27
+ describe "#run" do
28
+ it "calls UV.run" do
29
+ UV.should_receive(:run).with(loop_pointer)
30
+
31
+ subject.run
32
+ end
33
+ end
34
+
35
+ describe "#run_once" do
36
+ it "calls UV.run_once" do
37
+ UV.should_receive(:run_once).with(loop_pointer)
38
+
39
+ subject.run_once
40
+ end
41
+ end
42
+
43
+ describe "#update_time" do
44
+ it "calls UV.update_time" do
45
+ UV.should_receive(:update_time).with(loop_pointer)
46
+
47
+ subject.update_time
48
+ end
49
+ end
50
+
51
+ describe "#now" do
52
+ let(:now) { Time.now }
53
+
54
+ it "calls UV.now" do
55
+ UV.should_receive(:now).with(loop_pointer).and_return(now)
56
+
57
+ subject.now.should == now
58
+ end
59
+ end
60
+
61
+ describe "#last_error" do
62
+ let(:error) { double() }
63
+
64
+ it "calls UV.last_error" do
65
+ UV.should_receive(:last_error).with(loop_pointer).and_return(error)
66
+ UV.should_receive(:err_name).with(error).and_return("EINVAL")
67
+ UV.should_receive(:strerror).with(error).and_return("invalid argument")
68
+
69
+ subject.last_error.should == UV::Error::EINVAL.new("invalid argument")
70
+ end
71
+ end
72
+
73
+ describe "#timer" do
74
+ let(:timer_pointer) { double() }
75
+ let(:timer) { double() }
76
+
77
+ it "calls UV.timer_init" do
78
+ UV.should_receive(:create_handle).with(:uv_timer).and_return(timer_pointer)
79
+ UV.should_receive(:timer_init).with(loop_pointer, timer_pointer)
80
+ UV::Timer.should_receive(:new).with(subject, timer_pointer).and_return(timer)
81
+
82
+ subject.timer.should == timer
83
+ end
84
+ end
85
+
86
+ describe "#tcp" do
87
+ let(:tcp_pointer) { double() }
88
+ let(:tcp) { double() }
89
+
90
+ it "calls UV.tcp_init" do
91
+ UV.should_receive(:create_handle).with(:uv_tcp).and_return(tcp_pointer)
92
+ UV.should_receive(:tcp_init).with(loop_pointer, tcp_pointer)
93
+ UV::TCP.should_receive(:new).with(subject, tcp_pointer).and_return(tcp)
94
+
95
+ subject.tcp.should == tcp
96
+ end
97
+ end
98
+
99
+ describe "#tty" do
100
+ let(:tty_pointer) { double() }
101
+ let(:tty) { double() }
102
+ let(:fileno) { 6555 }
103
+
104
+ before(:each) do
105
+ UV.should_receive(:create_handle).with(:uv_tty).and_return(tty_pointer)
106
+ UV::TTY.should_receive(:new).with(subject, tty_pointer).and_return(tty)
107
+ end
108
+
109
+ context "readable" do
110
+ it "calls UV.tty_init" do
111
+ UV.should_receive(:tty_init).with(loop_pointer, tty_pointer, fileno, 1)
112
+
113
+ subject.tty(fileno, true).should == tty
114
+ end
115
+ end
116
+
117
+ context "not readable" do
118
+ it "calls UV.tty_init" do
119
+ UV.should_receive(:tty_init).with(loop_pointer, tty_pointer, fileno, 0)
120
+
121
+ subject.tty(fileno, false).should == tty
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "#pipe" do
127
+ let(:pipe_pointer) { double() }
128
+ let(:pipe) { double() }
129
+
130
+ before(:each) do
131
+ UV.should_receive(:create_handle).with(:uv_pipe).and_return(pipe_pointer)
132
+ UV::Pipe.should_receive(:new).with(subject, pipe_pointer).and_return(pipe)
133
+ end
134
+
135
+ context "with ipc" do
136
+ it "calls UV.pipe_init" do
137
+ UV.should_receive(:pipe_init).with(loop_pointer, pipe_pointer, 0)
138
+
139
+ subject.pipe.should == pipe
140
+ end
141
+ end
142
+
143
+ context "without ipc" do
144
+ it "calls UV.pipe_init" do
145
+ UV.should_receive(:pipe_init).with(loop_pointer, pipe_pointer, 1)
146
+
147
+ subject.pipe(true).should == pipe
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#prepare" do
153
+ let(:prepare_pointer) { double() }
154
+ let(:prepare) { double() }
155
+
156
+ it "calls UV.prepare_init" do
157
+ UV.should_receive(:create_handle).with(:uv_prepare).and_return(prepare_pointer)
158
+ UV.should_receive(:prepare_init).with(loop_pointer, prepare_pointer)
159
+ UV::Prepare.should_receive(:new).with(subject, prepare_pointer).and_return(prepare)
160
+
161
+ subject.prepare.should == prepare
162
+ end
163
+ end
164
+
165
+ describe "#check" do
166
+ let(:check_pointer) { double() }
167
+ let(:check) { double() }
168
+
169
+ it "calls UV.check_init" do
170
+ UV.should_receive(:create_handle).with(:uv_check).and_return(check_pointer)
171
+ UV.should_receive(:check_init).with(loop_pointer, check_pointer)
172
+ UV::Check.should_receive(:new).with(subject, check_pointer).and_return(check)
173
+
174
+ subject.check.should == check
175
+ end
176
+ end
177
+
178
+ describe "#idle" do
179
+ let(:idle_pointer) { double() }
180
+ let(:idle) { double() }
181
+
182
+ it "calls UV.idle_init" do
183
+ UV.should_receive(:create_handle).with(:uv_idle).and_return(idle_pointer)
184
+ UV.should_receive(:idle_init).with(loop_pointer, idle_pointer)
185
+ UV::Idle.should_receive(:new).with(subject, idle_pointer).and_return(idle)
186
+
187
+ subject.idle.should == idle
188
+ end
189
+ end
190
+
191
+ describe "#async" do
192
+ let(:async_pointer) { double() }
193
+ let(:async_callback) { double() }
194
+ let(:async) { double() }
195
+
196
+ it "requires a block" do
197
+ expect { subject.async }.to raise_error(ArgumentError)
198
+ end
199
+
200
+ it "calls UV.async_init" do
201
+ UV.should_receive(:create_handle).with(:uv_async).and_return(async_pointer)
202
+ UV.should_receive(:async_init).with(loop_pointer, async_pointer, async_callback)
203
+ UV::Async.should_receive(:new).with(subject, async_pointer).and_return(async)
204
+ async.should_receive(:callback).once.with(:on_async).and_return(async_callback)
205
+
206
+ handle = subject.async { |e| }
207
+ handle.should == async
208
+ end
209
+ end
210
+
211
+ describe "#fs" do
212
+ let(:filesystem) { double() }
213
+
214
+ it "instantiates UV::Filesystem" do
215
+ UV::Filesystem.should_receive(:new).once.with(subject).and_return(filesystem)
216
+
217
+ subject.fs.should == filesystem
218
+ end
219
+ end
220
+
221
+ describe "#fs_event" do
222
+ let(:filename) { '/path/to/watch' }
223
+ let(:fs_event_pointer) { double() }
224
+ let(:fs_event_callback) { double() }
225
+ let(:fs_event) { double() }
226
+
227
+ it "requires a block" do
228
+ expect { subject.fs_event(filename) }.to raise_error(ArgumentError)
229
+ end
230
+
231
+ it "calls UV.fs_event_init" do
232
+ UV.should_receive(:create_handle).with(:uv_fs_event).and_return(fs_event_pointer)
233
+ UV.should_receive(:fs_event_init).with(loop_pointer, fs_event_pointer, filename, fs_event_callback, 0)
234
+ UV::FSEvent.should_receive(:new).with(subject, fs_event_pointer).and_return(fs_event)
235
+ fs_event.should_receive(:callback).once.with(:on_fs_event).and_return(fs_event_callback)
236
+
237
+ handle = subject.fs_event(filename) { |e, filename, type| }
238
+ handle.should == fs_event
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Pipe do
4
+ let(:handle_name) { :pipe }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::Pipe.new(loop, pointer) }
8
+
9
+ it_behaves_like 'a handle'
10
+ it_behaves_like 'a stream'
11
+
12
+ describe "#open" do
13
+ let(:fileno) { 6555 }
14
+
15
+ it "calls UV.pipe_open" do
16
+ UV.should_receive(:pipe_open).with(pointer, fileno)
17
+
18
+ subject.open(fileno)
19
+ end
20
+ end
21
+
22
+ describe "#bind" do
23
+ let(:name) { "/tmp/filename.ipc" }
24
+
25
+ it "calls UV.pipe_bind" do
26
+ UV.should_receive(:pipe_bind).with(pointer, name)
27
+
28
+ subject.bind(name)
29
+ end
30
+ end
31
+
32
+ describe "#connect" do
33
+ let(:name) { "/tmp/filename.ipc" }
34
+ let(:connect_request) { double() }
35
+
36
+ it "requires a block" do
37
+ expect{ subject.connect(name) }.to raise_error(ArgumentError)
38
+ end
39
+
40
+ it "calls UV.pipe_connect" do
41
+ UV.should_receive(:create_request).with(:uv_connect).and_return(connect_request)
42
+ UV.should_receive(:pipe_connect).with(connect_request, pointer, name, subject.method(:on_connect))
43
+
44
+ subject.connect(name) { |e| }
45
+ end
46
+ end
47
+
48
+ describe "#pending_instances=" do
49
+ it "calls UV.pipe_pending_instances" do
50
+ UV.should_receive(:pipe_pending_instances).with(pointer, 5)
51
+ subject.pending_instances = 5
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Prepare do
4
+ let(:handle_name) { :prepare }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::Prepare.new(loop, pointer) }
8
+
9
+ it_behaves_like 'a handle'
10
+
11
+ describe "#start" do
12
+ it "requires a block" do
13
+ expect { subject.start }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it "calls UV.prepare_start" do
17
+ UV.should_receive(:prepare_start).with(pointer, subject.method(:on_prepare))
18
+
19
+ subject.start { |e| }
20
+ end
21
+ end
22
+
23
+ describe "#stop" do
24
+ it "calls UV.prepare_stop" do
25
+ UV.should_receive(:prepare_stop).with(pointer)
26
+
27
+ subject.stop
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::TCP do
4
+ let(:handle_name) { :tcp }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::TCP.new(loop, pointer) }
8
+
9
+ it_behaves_like 'a handle'
10
+ it_behaves_like 'a stream'
11
+
12
+ describe "#bind" do
13
+ let(:ip_addr) { double() }
14
+ let(:port) { 0 }
15
+
16
+ context "ipv4" do
17
+ let(:ip) { "0.0.0.0" }
18
+
19
+ it "calls UV.tcp_bind" do
20
+ UV.should_receive(:ip4_addr).with(ip, port).and_return(ip_addr)
21
+ UV.should_receive(:tcp_bind).with(pointer, ip_addr)
22
+
23
+ subject.bind(ip, port)
24
+ end
25
+ end
26
+
27
+ context "ipv6" do
28
+ let(:ip) { "::" }
29
+
30
+ it "calls UV.tcp_bind6" do
31
+ UV.should_receive(:ip6_addr).with(ip, port).and_return(ip_addr)
32
+ UV.should_receive(:tcp_bind6).with(pointer, ip_addr)
33
+
34
+ subject.bind(ip, port)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#connect" do
40
+ let(:connect_request) { double() }
41
+ let(:ip_addr) { double() }
42
+ let(:port) { 0 }
43
+
44
+ it "requires a block" do
45
+ expect { subject.connect("0.0.0.0", port) }.to raise_error(ArgumentError)
46
+ end
47
+
48
+ context "ipv4" do
49
+ let(:ip) { "0.0.0.0" }
50
+
51
+ it "calls UV.tcp_connect" do
52
+ UV.should_receive(:create_request).with(:uv_connect).and_return(connect_request)
53
+ UV.should_receive(:ip4_addr).with(ip, port).and_return(ip_addr)
54
+ UV.should_receive(:tcp_connect).with(connect_request, pointer, ip_addr, subject.method(:on_connect))
55
+
56
+ subject.connect(ip, port) { |e| }
57
+ end
58
+ end
59
+
60
+ context "ipv6" do
61
+ let(:ip) { "::" }
62
+
63
+ it "calls UV.tcp_connect6" do
64
+ UV.should_receive(:create_request).with(:uv_connect).and_return(connect_request)
65
+ UV.should_receive(:ip6_addr).with(ip, port).and_return(ip_addr)
66
+ UV.should_receive(:tcp_connect6).with(connect_request, pointer, ip_addr, subject.method(:on_connect))
67
+
68
+ subject.connect(ip, port) { |e| }
69
+ end
70
+ end
71
+ end
72
+
73
+ # describe "#sockname" do
74
+ # let(:sockaddr) { double() }
75
+ # let(:len) { 15 }
76
+ #
77
+ # it "calls UV.tcp_getsockname" do
78
+ # UV.should_receive(:tcp_getsockname).with(pointer, sockaddr, len)
79
+ # end
80
+ # end
81
+ #
82
+ # describe "#peername" do
83
+ # end
84
+
85
+ describe "#enable_nodelay" do
86
+ it "calls UV.tcp_nodelay" do
87
+ UV.should_receive(:tcp_nodelay).with(pointer, 1)
88
+
89
+ subject.enable_nodelay
90
+ end
91
+ end
92
+
93
+ describe "#disable_nodelay" do
94
+ it "calls UV.tcp_nodelay" do
95
+ UV.should_receive(:tcp_nodelay).with(pointer, 0)
96
+
97
+ subject.disable_nodelay
98
+ end
99
+ end
100
+
101
+ describe "#enable_keepalive" do
102
+ let(:keepalive_delay) { 150 }
103
+
104
+ it "calls UV.tcp_keepalive" do
105
+ UV.should_receive(:tcp_keepalive).with(pointer, 1, keepalive_delay)
106
+
107
+ subject.enable_keepalive(keepalive_delay)
108
+ end
109
+ end
110
+
111
+ describe "#disable_keepalive" do
112
+ it "calls UV.tcp_keepalive" do
113
+ UV.should_receive(:tcp_keepalive).with(pointer, 0, 0)
114
+
115
+ subject.disable_keepalive
116
+ end
117
+ end
118
+
119
+ describe "#enable_simultaneous_accepts" do
120
+ it "calls UV.tcp_simultaneous_accepts" do
121
+ UV.should_receive(:tcp_simultaneous_accepts).with(pointer, 1)
122
+
123
+ subject.enable_simultaneous_accepts
124
+ end
125
+ end
126
+
127
+ describe "#disable_simultaneous_accepts" do
128
+ it "calls UV.tcp_simultaneous_accepts" do
129
+ UV.should_receive(:tcp_simultaneous_accepts).with(pointer, 0)
130
+
131
+ subject.disable_simultaneous_accepts
132
+ end
133
+ end
134
+ end