uvrb 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/uv.rb +7 -4
- data/lib/uv/assertions.rb +7 -0
- data/lib/uv/handle.rb +16 -2
- data/lib/uv/idle.rb +1 -0
- data/lib/uv/listener.rb +15 -13
- data/lib/uv/loop.rb +14 -0
- data/lib/uv/resource.rb +1 -1
- data/lib/uv/signal.rb +29 -0
- data/lib/uv/tcp.rb +6 -0
- data/lib/uv/types.rb +2 -0
- data/lib/uv/types/unix.rb +4 -0
- data/lib/uv/types/windows.rb +2 -0
- data/lib/uv/udp.rb +6 -0
- data/lib/uv/version.rb +1 -1
- data/spec/uv/loop_spec.rb +8 -0
- data/spec/uv/signal_spec.rb +32 -0
- data/spec/uv/tcp_spec.rb +10 -0
- data/spec/uv/udp_spec.rb +10 -0
- metadata +27 -18
data/lib/uv.rb
CHANGED
@@ -81,7 +81,7 @@ module UV
|
|
81
81
|
attach_function :shutdown, :uv_shutdown, [:uv_shutdown_t, :uv_stream_t, :uv_shutdown_cb], :int, :blocking => true
|
82
82
|
|
83
83
|
attach_function :tcp_init, :uv_tcp_init, [:uv_loop_t, :uv_tcp_t], :int, :blocking => true
|
84
|
-
|
84
|
+
attach_function :tcp_open, :uv_tcp_open, [:uv_tcp_t, :uv_os_sock_t], :int, :blocking => true
|
85
85
|
attach_function :tcp_nodelay, :uv_tcp_nodelay, [:uv_tcp_t, :int], :int, :blocking => true
|
86
86
|
attach_function :tcp_keepalive, :uv_tcp_keepalive, [:uv_tcp_t, :int, :uint], :int, :blocking => true
|
87
87
|
attach_function :tcp_simultaneous_accepts, :uv_tcp_simultaneous_accepts, [:uv_tcp_t, :int], :int, :blocking => true
|
@@ -93,6 +93,7 @@ module UV
|
|
93
93
|
attach_function :tcp_connect6, :uv_tcp_connect6, [:uv_connect_t, :uv_tcp_t, :sockaddr_in6, :uv_connect_cb], :int, :blocking => true
|
94
94
|
|
95
95
|
attach_function :udp_init, :uv_udp_init, [:uv_loop_t, :uv_udp_t], :int, :blocking => true
|
96
|
+
attach_function :udp_open, :uv_udp_open, [:uv_udp_t, :uv_os_sock_t], :int, :blocking => true
|
96
97
|
attach_function :udp_bind, :uv_udp_bind, [:uv_udp_t, :sockaddr_in, :uint], :int, :blocking => true
|
97
98
|
attach_function :udp_bind6, :uv_udp_bind6, [:uv_udp_t, :sockaddr_in6, :uint], :int, :blocking => true
|
98
99
|
attach_function :udp_getsockname, :uv_udp_getsockname, [:uv_udp_t, :pointer, :pointer], :int, :blocking => true
|
@@ -141,6 +142,10 @@ module UV
|
|
141
142
|
attach_function :timer_set_repeat, :uv_timer_set_repeat, [:uv_timer_t, :int64_t], :void, :blocking => true
|
142
143
|
attach_function :timer_get_repeat, :uv_timer_get_repeat, [:uv_timer_t], :int64_t, :blocking => true
|
143
144
|
|
145
|
+
attach_function :signal_init, :uv_signal_init, [:uv_loop_t, :uv_signal_t], :int, :blocking => true
|
146
|
+
attach_function :signal_start, :uv_signal_start, [:uv_signal_t, :uv_signal_cb, :int], :int, :blocking => true
|
147
|
+
attach_function :signal_stop, :uv_signal_stop, [:uv_signal_t], :int, :blocking => true
|
148
|
+
|
144
149
|
#attach_function :ares_init_options, :uv_ares_init_options, [:uv_loop_t, :ares_channel, :ares_options, :int], :int
|
145
150
|
#attach_function :ares_destroy, :uv_ares_destroy, [:uv_loop_t, :ares_channel], :void
|
146
151
|
|
@@ -239,9 +244,6 @@ module UV
|
|
239
244
|
attach_function :handle_size, :uv_handle_size, [:uv_handle_type], :size_t, :blocking => true
|
240
245
|
attach_function :req_size, :uv_req_size, [:uv_req_type], :size_t, :blocking => true
|
241
246
|
|
242
|
-
# This function is attached differently in windows - see ./types/windows.rb
|
243
|
-
attach_function :ntohs, [:ushort], :ushort, :blocking => true unless FFI::Platform.windows?
|
244
|
-
|
245
247
|
|
246
248
|
def self.create_handle(type)
|
247
249
|
LIBC.malloc(UV.handle_size(type))
|
@@ -268,6 +270,7 @@ module UV
|
|
268
270
|
autoload :Idle, 'uv/idle'
|
269
271
|
autoload :Async, 'uv/async'
|
270
272
|
autoload :Work, 'uv/work'
|
273
|
+
autoload :Signal, 'uv/signal'
|
271
274
|
autoload :Filesystem, 'uv/filesystem'
|
272
275
|
autoload :File, 'uv/file'
|
273
276
|
autoload :FSEvent, 'uv/fs_event'
|
data/lib/uv/assertions.rb
CHANGED
@@ -26,5 +26,12 @@ module UV
|
|
26
26
|
raise ArgumentError, msg, caller
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
def assert_signal(signo, msg = nil)
|
31
|
+
if not ::Signal.list.values.include?(signo)
|
32
|
+
msg ||= "undefined signal number: #{signo}"
|
33
|
+
raise ArgumentError, msg, caller
|
34
|
+
end
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
data/lib/uv/handle.rb
CHANGED
@@ -2,8 +2,16 @@ module UV
|
|
2
2
|
module Handle
|
3
3
|
include Assertions, Resource, Listener
|
4
4
|
|
5
|
+
class << self
|
6
|
+
def close(handle)
|
7
|
+
proc { UV.close(handle, UV.method(:free)) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def initialize(loop, pointer)
|
6
12
|
@loop, @pointer = loop, pointer
|
13
|
+
|
14
|
+
ObjectSpace.define_finalizer(self, Handle.close(@pointer))
|
7
15
|
end
|
8
16
|
|
9
17
|
# Public: Increment internal ref counter for the handle on the loop. Useful for
|
@@ -27,7 +35,11 @@ module UV
|
|
27
35
|
end
|
28
36
|
|
29
37
|
def close(&block)
|
30
|
-
if
|
38
|
+
return if @pointer.nil?
|
39
|
+
|
40
|
+
ObjectSpace.undefine_finalizer(self)
|
41
|
+
|
42
|
+
if block
|
31
43
|
assert_block(block)
|
32
44
|
assert_arity(0, block)
|
33
45
|
|
@@ -61,8 +73,10 @@ module UV
|
|
61
73
|
def on_close(pointer)
|
62
74
|
UV.free(pointer)
|
63
75
|
clear_callbacks
|
64
|
-
|
76
|
+
|
65
77
|
@close_block.call unless @close_block.nil?
|
78
|
+
|
79
|
+
@pointer = nil
|
66
80
|
end
|
67
81
|
end
|
68
82
|
end
|
data/lib/uv/idle.rb
CHANGED
data/lib/uv/listener.rb
CHANGED
@@ -2,25 +2,27 @@ require 'set'
|
|
2
2
|
|
3
3
|
module UV
|
4
4
|
module Listener
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
@@callbacks = Hash.new { |hash, object_id| hash[object_id] = Hash.new }
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def define_callback(object_id, name, callback)
|
9
|
+
@@callbacks[object_id][name] ||= callback
|
10
|
+
end
|
11
|
+
|
12
|
+
def undefine_callbacks(object_id)
|
13
|
+
@@callbacks.delete(object_id)
|
14
|
+
nil
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
18
|
+
private
|
19
|
+
|
10
20
|
def callback(name)
|
11
|
-
|
12
|
-
unless self.class.const_defined?(const_name)
|
13
|
-
callbacks << const_name
|
14
|
-
self.class.const_set(const_name, method(name))
|
15
|
-
end
|
16
|
-
self.class.const_get(const_name)
|
21
|
+
Listener.define_callback(object_id, name, method(name))
|
17
22
|
end
|
18
23
|
|
19
24
|
def clear_callbacks
|
20
|
-
|
21
|
-
self.class.send(:remove_const, name)
|
22
|
-
end
|
23
|
-
callbacks.clear
|
25
|
+
Listener.undefine_callbacks(object_id)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
data/lib/uv/loop.rb
CHANGED
@@ -105,6 +105,10 @@ module UV
|
|
105
105
|
run(:UV_RUN_ONCE)
|
106
106
|
end
|
107
107
|
|
108
|
+
def stop
|
109
|
+
check_result! UV.stop(@pointer)
|
110
|
+
end
|
111
|
+
|
108
112
|
# Public: forces loop time update, useful for getting more granular times
|
109
113
|
#
|
110
114
|
# Returns nothing
|
@@ -280,6 +284,16 @@ module UV
|
|
280
284
|
fs_event
|
281
285
|
end
|
282
286
|
|
287
|
+
# Public: Get a new Signal handle
|
288
|
+
#
|
289
|
+
# Returns UV::Signal
|
290
|
+
def signal
|
291
|
+
signal_ptr = UV.create_handle(:uv_signal)
|
292
|
+
|
293
|
+
check_result! UV.signal_init(@pointer, signal_ptr)
|
294
|
+
Signal.new(self, signal_ptr)
|
295
|
+
end
|
296
|
+
|
283
297
|
# Internal: Get a hold of internal loop pointer instance
|
284
298
|
#
|
285
299
|
# Returns FFI::Pointer
|
data/lib/uv/resource.rb
CHANGED
data/lib/uv/signal.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module UV
|
2
|
+
class Signal
|
3
|
+
include Assertions, Handle
|
4
|
+
|
5
|
+
def start(signum, &block)
|
6
|
+
assert_signal(signum)
|
7
|
+
assert_block(block)
|
8
|
+
assert_arity(1, block)
|
9
|
+
|
10
|
+
@signal_block = block
|
11
|
+
|
12
|
+
check_result! UV.signal_start(handle, callback(:on_signal), signum)
|
13
|
+
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def stop
|
18
|
+
check_result! UV.signal_stop(handle)
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def on_signal(handle, status)
|
26
|
+
@signal_block.call(check_result(status))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/uv/tcp.rb
CHANGED
data/lib/uv/types.rb
CHANGED
@@ -181,6 +181,7 @@ module UV
|
|
181
181
|
typedef :pointer, :uv_write_t
|
182
182
|
typedef :pointer, :uv_connect_t
|
183
183
|
typedef :pointer, :uv_udp_send_t
|
184
|
+
typedef :pointer, :uv_signal_t
|
184
185
|
typedef :int, :uv_file
|
185
186
|
typedef :pointer, :ares_channel
|
186
187
|
typedef :pointer, :ares_options
|
@@ -213,6 +214,7 @@ module UV
|
|
213
214
|
callback :uv_prepare_cb, [:uv_prepare_t, :status], :void
|
214
215
|
callback :uv_check_cb, [:uv_check_t, :status], :void
|
215
216
|
callback :uv_idle_cb, [:uv_idle_t, :status], :void
|
217
|
+
callback :uv_signal_cb, [:uv_signal_t, :status], :void
|
216
218
|
callback :uv_getaddrinfo_cb, [:uv_getaddrinfo_t, :status, :addrinfo], :void
|
217
219
|
callback :uv_exit_cb, [:uv_process_t, :int, :int], :void
|
218
220
|
callback :uv_walk_cb, [:uv_handle_t, :pointer], :void
|
data/lib/uv/types/unix.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module UV
|
2
|
+
typedef :int, :uv_os_sock_t
|
3
|
+
|
2
4
|
class UvBuf < FFI::Struct
|
3
5
|
layout :base, :pointer, :len, :size_t
|
4
6
|
end
|
@@ -9,4 +11,6 @@ module UV
|
|
9
11
|
:st_blksize, :blksize_t, :st_blocks, :blkcnt_t, :st_atime, :time_t,
|
10
12
|
:st_mtime, :time_t, :st_ctime, :time_t
|
11
13
|
end
|
14
|
+
|
15
|
+
attach_function :ntohs, [:ushort], :ushort, :blocking => true
|
12
16
|
end
|
data/lib/uv/types/windows.rb
CHANGED
data/lib/uv/udp.rb
CHANGED
@@ -2,6 +2,12 @@ module UV
|
|
2
2
|
class UDP
|
3
3
|
include Handle, Net
|
4
4
|
|
5
|
+
def open(fd)
|
6
|
+
check_result! UV.udp_open(handle, fd)
|
7
|
+
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
5
11
|
def bind(ip, port, ipv6_only = false)
|
6
12
|
assert_type(String, ip, "ip must be a String")
|
7
13
|
assert_type(Integer, port, "port must be an Integer")
|
data/lib/uv/version.rb
CHANGED
data/spec/uv/loop_spec.rb
CHANGED
@@ -32,6 +32,14 @@ describe UV::Loop do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "#stop" do
|
36
|
+
it "calls UV.stop" do
|
37
|
+
UV.should_receive(:stop).with(loop_pointer)
|
38
|
+
|
39
|
+
subject.stop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
describe "#update_time" do
|
36
44
|
it "calls UV.update_time" do
|
37
45
|
UV.should_receive(:update_time).with(loop_pointer)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe UV::Signal do
|
4
|
+
let(:handle_name) { :signal }
|
5
|
+
let(:loop) { double() }
|
6
|
+
let(:pointer) { double() }
|
7
|
+
subject { UV::Signal.new(loop, pointer) }
|
8
|
+
|
9
|
+
it_behaves_like 'a handle'
|
10
|
+
|
11
|
+
describe "#start" do
|
12
|
+
let(:signo) { 2 }
|
13
|
+
|
14
|
+
it "requires a block" do
|
15
|
+
expect { subject.start(signo) }.to raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "calls UV.signal_start" do
|
19
|
+
UV.should_receive(:signal_start).with(pointer, subject.method(:on_signal), signo)
|
20
|
+
|
21
|
+
subject.start(signo) { |e| }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#stop" do
|
26
|
+
it "calls UV.signal_stop" do
|
27
|
+
UV.should_receive(:signal_stop).with(pointer)
|
28
|
+
|
29
|
+
subject.stop
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/uv/tcp_spec.rb
CHANGED
@@ -9,6 +9,16 @@ describe UV::TCP do
|
|
9
9
|
it_behaves_like 'a handle'
|
10
10
|
it_behaves_like 'a stream'
|
11
11
|
|
12
|
+
describe "#open" do
|
13
|
+
let(:fd) { 4 }
|
14
|
+
|
15
|
+
it "calls UV.tcp_open" do
|
16
|
+
UV.should_receive(:tcp_open).with(pointer, fd)
|
17
|
+
|
18
|
+
subject.open(fd)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
describe "#bind" do
|
13
23
|
let(:ip_addr) { double() }
|
14
24
|
let(:port) { 0 }
|
data/spec/uv/udp_spec.rb
CHANGED
@@ -8,6 +8,16 @@ describe UV::UDP do
|
|
8
8
|
|
9
9
|
it_behaves_like 'a handle'
|
10
10
|
|
11
|
+
describe "#open" do
|
12
|
+
let(:fd) { 4 }
|
13
|
+
|
14
|
+
it "calls UV.udp_open" do
|
15
|
+
UV.should_receive(:udp_open).with(pointer, fd)
|
16
|
+
|
17
|
+
subject.open(fd)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
describe "#bind" do
|
12
22
|
let(:ip_addr) { double() }
|
13
23
|
let(:port) { 0 }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uvrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/uv/pipe.rb
|
161
161
|
- lib/uv/prepare.rb
|
162
162
|
- lib/uv/resource.rb
|
163
|
+
- lib/uv/signal.rb
|
163
164
|
- lib/uv/stream.rb
|
164
165
|
- lib/uv/tasks.rb
|
165
166
|
- lib/uv/tasks/mac.rb
|
@@ -189,6 +190,7 @@ files:
|
|
189
190
|
- spec/uv/loop_spec.rb
|
190
191
|
- spec/uv/pipe_spec.rb
|
191
192
|
- spec/uv/prepare_spec.rb
|
193
|
+
- spec/uv/signal_spec.rb
|
192
194
|
- spec/uv/tcp_spec.rb
|
193
195
|
- spec/uv/timer_spec.rb
|
194
196
|
- spec/uv/tty_spec.rb
|
@@ -199,34 +201,37 @@ files:
|
|
199
201
|
- ext/libuv/AUTHORS
|
200
202
|
- ext/libuv/ChangeLog
|
201
203
|
- ext/libuv/LICENSE
|
202
|
-
- ext/libuv/Makefile
|
204
|
+
- ext/libuv/Makefile.am
|
205
|
+
- ext/libuv/Makefile.mingw
|
203
206
|
- ext/libuv/README.md
|
204
|
-
- ext/libuv/
|
207
|
+
- ext/libuv/android-configure
|
208
|
+
- ext/libuv/autogen.sh
|
205
209
|
- ext/libuv/checksparse.sh
|
206
210
|
- ext/libuv/common.gypi
|
207
|
-
- ext/libuv/
|
208
|
-
- ext/libuv/config-unix.mk
|
211
|
+
- ext/libuv/configure.ac
|
209
212
|
- ext/libuv/gyp_uv
|
210
|
-
- ext/libuv/include/
|
211
|
-
- ext/libuv/include/
|
212
|
-
- ext/libuv/include/
|
213
|
-
- ext/libuv/include/uv-
|
214
|
-
- ext/libuv/include/uv-
|
215
|
-
- ext/libuv/include/uv-
|
216
|
-
- ext/libuv/include/uv-
|
217
|
-
- ext/libuv/include/uv-
|
218
|
-
- ext/libuv/include/uv-
|
213
|
+
- ext/libuv/include/pthread-fixes.h
|
214
|
+
- ext/libuv/include/stdint-msvc2008.h
|
215
|
+
- ext/libuv/include/tree.h
|
216
|
+
- ext/libuv/include/uv-bsd.h
|
217
|
+
- ext/libuv/include/uv-darwin.h
|
218
|
+
- ext/libuv/include/uv-errno.h
|
219
|
+
- ext/libuv/include/uv-linux.h
|
220
|
+
- ext/libuv/include/uv-sunos.h
|
221
|
+
- ext/libuv/include/uv-unix.h
|
222
|
+
- ext/libuv/include/uv-win.h
|
219
223
|
- ext/libuv/include/uv.h
|
224
|
+
- ext/libuv/m4/.gitignore
|
225
|
+
- ext/libuv/m4/dtrace.m4
|
220
226
|
- ext/libuv/src/fs-poll.c
|
221
227
|
- ext/libuv/src/inet.c
|
228
|
+
- ext/libuv/src/queue.h
|
222
229
|
- ext/libuv/src/unix/aix.c
|
223
230
|
- ext/libuv/src/unix/async.c
|
224
231
|
- ext/libuv/src/unix/core.c
|
225
|
-
- ext/libuv/src/unix/cygwin.c
|
226
232
|
- ext/libuv/src/unix/darwin-proctitle.c
|
227
233
|
- ext/libuv/src/unix/darwin.c
|
228
234
|
- ext/libuv/src/unix/dl.c
|
229
|
-
- ext/libuv/src/unix/error.c
|
230
235
|
- ext/libuv/src/unix/freebsd.c
|
231
236
|
- ext/libuv/src/unix/fs.c
|
232
237
|
- ext/libuv/src/unix/fsevents.c
|
@@ -245,6 +250,7 @@ files:
|
|
245
250
|
- ext/libuv/src/unix/poll.c
|
246
251
|
- ext/libuv/src/unix/process.c
|
247
252
|
- ext/libuv/src/unix/proctitle.c
|
253
|
+
- ext/libuv/src/unix/pthread-fixes.c
|
248
254
|
- ext/libuv/src/unix/signal.c
|
249
255
|
- ext/libuv/src/unix/stream.c
|
250
256
|
- ext/libuv/src/unix/sunos.c
|
@@ -322,6 +328,7 @@ files:
|
|
322
328
|
- ext/libuv/test/runner.h
|
323
329
|
- ext/libuv/test/task.h
|
324
330
|
- ext/libuv/test/test-active.c
|
331
|
+
- ext/libuv/test/test-async-null-cb.c
|
325
332
|
- ext/libuv/test/test-async.c
|
326
333
|
- ext/libuv/test/test-barrier.c
|
327
334
|
- ext/libuv/test/test-callback-order.c
|
@@ -344,6 +351,7 @@ files:
|
|
344
351
|
- ext/libuv/test/test-getsockname.c
|
345
352
|
- ext/libuv/test/test-hrtime.c
|
346
353
|
- ext/libuv/test/test-idle.c
|
354
|
+
- ext/libuv/test/test-ip6-addr.c
|
347
355
|
- ext/libuv/test/test-ipc-send-recv.c
|
348
356
|
- ext/libuv/test/test-ipc.c
|
349
357
|
- ext/libuv/test/test-list.h
|
@@ -424,7 +432,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
424
432
|
version: '0'
|
425
433
|
segments:
|
426
434
|
- 0
|
427
|
-
hash:
|
435
|
+
hash: 3415186922912615671
|
428
436
|
requirements:
|
429
437
|
- libuv
|
430
438
|
rubyforge_project:
|
@@ -451,6 +459,7 @@ test_files:
|
|
451
459
|
- spec/uv/loop_spec.rb
|
452
460
|
- spec/uv/pipe_spec.rb
|
453
461
|
- spec/uv/prepare_spec.rb
|
462
|
+
- spec/uv/signal_spec.rb
|
454
463
|
- spec/uv/tcp_spec.rb
|
455
464
|
- spec/uv/timer_spec.rb
|
456
465
|
- spec/uv/tty_spec.rb
|