rbuv 0.0.2 → 0.0.3

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.
data/spec/timer_spec.rb CHANGED
@@ -3,31 +3,31 @@ require 'spec_helper'
3
3
  describe Rbuv::Timer do
4
4
  it { should be_a_kind_of Rbuv::Handle }
5
5
 
6
- context "run in loop" do
7
- before(:each) { @skip_running_loop = false }
8
- after(:each) { Rbuv.run_loop unless @skip_running_loop }
9
-
10
- context "when timeout == 0" do
11
- context "#start" do
12
- it "when repeat == 0" do
13
- timer = Rbuv::Timer.new
6
+ context "when timeout == 0" do
7
+ context "#start" do
8
+ it "when repeat == 0" do
9
+ timer = Rbuv::Timer.new
14
10
 
15
- block = mock
16
- block.should_receive(:call).once
11
+ block = mock
12
+ block.should_receive(:call).once
17
13
 
14
+ Rbuv.run do
18
15
  timer.start 0, 0 do
19
16
  block.call
20
17
  end
21
18
  end
19
+ end
22
20
 
23
- it "when repeat != 0" do
24
- timer = Rbuv::Timer.new
21
+ it "when repeat != 0" do
22
+ timer = Rbuv::Timer.new
25
23
 
26
- block = mock
27
- count_limit = 10
28
- block.should_receive(:call).exactly(count_limit)
24
+ block = mock
25
+ count_limit = 10
26
+ block.should_receive(:call).exactly(count_limit)
29
27
 
30
- count = 0
28
+ count = 0
29
+
30
+ Rbuv.run do
31
31
  timer.start 0, 1 do |t|
32
32
  block.call
33
33
  count += 1
@@ -36,44 +36,52 @@ describe Rbuv::Timer do
36
36
  end
37
37
  end
38
38
  end
39
- end # context "#start"
39
+ end
40
+ end # context "#start"
40
41
 
41
- it "#stop" do
42
- timer = Rbuv::Timer.new
42
+ it "#stop" do
43
+ timer = Rbuv::Timer.new
43
44
 
44
- block = mock
45
- block.should_receive(:call).once
45
+ block = mock
46
+ block.should_receive(:call).once
46
47
 
48
+ Rbuv.run do
47
49
  timer.start 0, 1 do |t|
48
50
  block.call
49
51
  t.stop
50
52
  end
51
53
  end
54
+ end
52
55
 
53
- context "#active?" do
54
- it "should be false" do
55
- timer = Rbuv::Timer.new
56
+ context "#active?" do
57
+ it "should be false" do
58
+ timer = Rbuv::Timer.new
56
59
 
60
+ Rbuv.run do
57
61
  timer.start 0, 0 do |t|
58
62
  t.active?.should be_false
59
63
  end
60
64
  end
65
+ end
61
66
 
62
- it "should be true" do
63
- timer = Rbuv::Timer.new
67
+ it "should be true" do
68
+ timer = Rbuv::Timer.new
64
69
 
70
+ Rbuv.run do
65
71
  timer.start 0, 1 do |t|
66
72
  t.active?.should be_true
67
73
  t.stop
68
74
  end
69
75
  end
70
76
  end
77
+ end
71
78
 
72
- context "#repeat" do
73
- [0, 10, 100].each do |repeat|
74
- it "should eq #{repeat}" do
75
- timer = Rbuv::Timer.new
79
+ context "#repeat" do
80
+ [0, 10, 100].each do |repeat|
81
+ it "should eq #{repeat}" do
82
+ timer = Rbuv::Timer.new
76
83
 
84
+ Rbuv.run do
77
85
  timer.start 0, repeat do |t|
78
86
  t.repeat.should eq repeat
79
87
  t.stop
@@ -81,51 +89,60 @@ describe Rbuv::Timer do
81
89
  end
82
90
  end
83
91
  end
92
+ end
84
93
 
85
- context "#repeat=" do
86
- [0, 10, 100].each do |repeat|
87
- it "should eq #{repeat}" do
88
- timer = Rbuv::Timer.new
94
+ context "#repeat=" do
95
+ [0, 10, 100].each do |repeat|
96
+ it "should eq #{repeat}" do
97
+ timer = Rbuv::Timer.new
89
98
 
99
+ Rbuv.run do
90
100
  timer.start 0, 0 do |t|
91
101
  t.repeat = repeat
92
102
  end
93
- Rbuv.run_loop
94
- timer.repeat.should eq repeat
95
- @skip_running_loop = true
96
103
  end
104
+ timer.repeat.should eq repeat
97
105
  end
98
106
  end
107
+ end
99
108
 
100
- context ".start" do
101
- context 'be valid' do
102
- it "when repeat == 0" do
103
- block = mock
104
- block.should_receive(:call).once
109
+ context ".start" do
110
+ context 'be valid' do
111
+ it "when repeat == 0" do
112
+ block = mock
113
+ block.should_receive(:call).once
105
114
 
115
+ Rbuv.run do
106
116
  Rbuv::Timer.start(0, 0) { block.call }
107
117
  end
118
+ end
108
119
 
109
- it "when repeat != 0" do
110
- block = mock
111
- block.should_receive(:call).once
120
+ it "when repeat != 0" do
121
+ block = mock
122
+ block.should_receive(:call).once
112
123
 
124
+ Rbuv.run do
113
125
  Rbuv::Timer.start 0, 1 do |t|
114
126
  block.call
115
127
  t.stop
116
128
  end
117
129
  end
118
130
  end
131
+ end
119
132
 
120
- context "won't segfault" do
121
- it "when repeat == 0" do
133
+ context "won't segfault" do
134
+ it "when repeat == 0" do
135
+ Rbuv.run do
122
136
  Rbuv::Timer.start(0, 0) {}
123
- GC.start
124
137
  end
138
+ GC.start
139
+ end
125
140
 
126
- it "when repeat != 0" do
127
- count = 0
128
- count_limit = 10
141
+ it "when repeat != 0" do
142
+ count = 0
143
+ count_limit = 10
144
+
145
+ Rbuv.run do
129
146
  Rbuv::Timer.start 0, 1 do |timer|
130
147
  GC.start
131
148
  count += 1
@@ -133,12 +150,12 @@ describe Rbuv::Timer do
133
150
  timer.stop
134
151
  end
135
152
  end
136
- GC.start
137
153
  end
154
+ GC.start
138
155
  end
156
+ end
139
157
 
140
- end # context ".start"
158
+ end # context ".start"
141
159
 
142
- end # context "timeout == 0"
143
- end # context "run in loop"
160
+ end # context "timeout == 0"
144
161
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbuv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hanfei Shen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2013-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -301,24 +301,33 @@ files:
301
301
  - deps/libuv/test/test-walk-handles.c
302
302
  - deps/libuv/uv.gyp
303
303
  - deps/libuv/vcbuild.bat
304
- - ext/rbuv/debug.h
305
- - ext/rbuv/error.c
306
- - ext/rbuv/error.h
307
304
  - ext/rbuv/extconf.rb
308
- - ext/rbuv/handle.c
309
- - ext/rbuv/handle.h
310
305
  - ext/rbuv/libuv.mk
311
- - ext/rbuv/loop.c
312
- - ext/rbuv/loop.h
313
306
  - ext/rbuv/rbuv.c
314
307
  - ext/rbuv/rbuv.h
315
- - ext/rbuv/timer.c
316
- - ext/rbuv/timer.h
308
+ - ext/rbuv/rbuv_debug.h
309
+ - ext/rbuv/rbuv_error.c
310
+ - ext/rbuv/rbuv_error.h
311
+ - ext/rbuv/rbuv_handle.c
312
+ - ext/rbuv/rbuv_handle.h
313
+ - ext/rbuv/rbuv_loop.c
314
+ - ext/rbuv/rbuv_loop.h
315
+ - ext/rbuv/rbuv_signal.c
316
+ - ext/rbuv/rbuv_signal.h
317
+ - ext/rbuv/rbuv_stream.c
318
+ - ext/rbuv/rbuv_stream.h
319
+ - ext/rbuv/rbuv_tcp.c
320
+ - ext/rbuv/rbuv_tcp.h
321
+ - ext/rbuv/rbuv_timer.c
322
+ - ext/rbuv/rbuv_timer.h
317
323
  - lib/rbuv.rb
324
+ - lib/rbuv/signal.rb
318
325
  - lib/rbuv/timer.rb
319
326
  - lib/rbuv/version.rb
320
327
  - rbuv.gemspec
328
+ - spec/signal_spec.rb
321
329
  - spec/spec_helper.rb
330
+ - spec/tcp_spec.rb
322
331
  - spec/timer_spec.rb
323
332
  homepage: https://github.com/rbuv/rbuv
324
333
  licenses:
@@ -345,5 +354,7 @@ signing_key:
345
354
  specification_version: 4
346
355
  summary: libuv binding for Ruby
347
356
  test_files:
357
+ - spec/signal_spec.rb
348
358
  - spec/spec_helper.rb
359
+ - spec/tcp_spec.rb
349
360
  - spec/timer_spec.rb
data/ext/rbuv/handle.c DELETED
@@ -1,40 +0,0 @@
1
- #include "handle.h"
2
-
3
- struct rbuv_handle_s {
4
- uv_handle_t *uv_handle;
5
- };
6
-
7
- VALUE cRbuvHandle;
8
-
9
- /* Methods */
10
- static VALUE rbuv_handle_is_active(VALUE self);
11
-
12
- /* Private methods */
13
- static void _uv_handle_on_close(uv_handle_t *uv_handle);
14
-
15
- void Init_rbuv_handle() {
16
- cRbuvHandle = rb_define_class_under(mRbuv, "Handle", rb_cObject);
17
- rb_undef_alloc_func(cRbuvHandle);
18
-
19
- rb_define_method(cRbuvHandle, "active?", rbuv_handle_is_active, 0);
20
- }
21
-
22
- VALUE rbuv_handle_is_active(VALUE self) {
23
- rbuv_handle_t *rbuv_handle;
24
-
25
- Data_Get_Struct(self, rbuv_handle_t, rbuv_handle);
26
-
27
- return uv_is_active(rbuv_handle->uv_handle) ? Qtrue : Qfalse;
28
- }
29
-
30
- void rbuv_handle_close(rbuv_handle_t *rbuv_handle) {
31
- assert(rbuv_handle);
32
- assert(rbuv_handle->uv_handle);
33
- uv_close(rbuv_handle->uv_handle, _uv_handle_on_close);
34
- }
35
-
36
- void _uv_handle_on_close(uv_handle_t *uv_handle) {
37
- RBUV_DEBUG_LOG_DETAIL("uv_handle: %p, handle: %ld",
38
- uv_handle, (VALUE)uv_handle->data);
39
- free(uv_handle);
40
- }
data/ext/rbuv/handle.h DELETED
@@ -1,14 +0,0 @@
1
- #ifndef RBUV_HANDLE_H_
2
- #define RBUV_HANDLE_H_
3
-
4
- #include "rbuv.h"
5
-
6
- typedef struct rbuv_handle_s rbuv_handle_t;
7
-
8
- extern VALUE cRbuvHandle;
9
-
10
- void Init_rbuv_handle();
11
-
12
- void rbuv_handle_close(rbuv_handle_t *rbuv_handle);
13
-
14
- #endif /* RBUV_HANDLE_H_ */