libuv 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/libuv/async.rb +9 -4
- data/lib/libuv/check.rb +3 -0
- data/lib/libuv/dns.rb +6 -1
- data/lib/libuv/ext/ext.rb +1 -0
- data/lib/libuv/ext/tasks.rb +1 -1
- data/lib/libuv/file.rb +29 -12
- data/lib/libuv/filesystem.rb +32 -14
- data/lib/libuv/fs_event.rb +6 -3
- data/lib/libuv/handle.rb +7 -1
- data/lib/libuv/idle.rb +7 -4
- data/lib/libuv/mixins/fs_checks.rb +14 -1
- data/lib/libuv/mixins/listener.rb +47 -15
- data/lib/libuv/mixins/stream.rb +15 -1
- data/lib/libuv/pipe.rb +20 -18
- data/lib/libuv/prepare.rb +3 -0
- data/lib/libuv/signal.rb +3 -0
- data/lib/libuv/tcp.rb +26 -6
- data/lib/libuv/timer.rb +4 -0
- data/lib/libuv/udp.rb +8 -1
- data/lib/libuv/version.rb +1 -1
- data/lib/libuv/work.rb +10 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b69d133fc3c1af085d7028273dd69cb700a8d4d
|
4
|
+
data.tar.gz: 19271270d05dab8ad4a49eabacc269d2198c9447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3f1a81309e2a576b1b1315b8bea853354b0a5d7fad86afb296c9aeda9bb5458ca88c6579d9cf73e16702f1810b58f768eb6900a29b31d0465d38b5b4d2fdde8
|
7
|
+
data.tar.gz: a3366d0120f38dcbc7ef7bf91c8e95e3adbf68a28535ef32ddfff202c089e1c36cab21dc33b855c53b121af11bcb4d535fa916f22b4b7b1ca1272f09ccdda799
|
data/.travis.yml
CHANGED
data/lib/libuv/async.rb
CHANGED
@@ -2,12 +2,17 @@ module Libuv
|
|
2
2
|
class Async < Handle
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
define_callback function: :on_async
|
6
|
+
|
7
|
+
|
8
|
+
# @param thread [::Libuv::Loop] loop this async callback will be associated
|
9
|
+
def initialize(thread, callback = nil, &blk)
|
10
|
+
@loop = thread
|
8
11
|
@callback = callback || blk
|
12
|
+
|
9
13
|
async_ptr = ::Libuv::Ext.allocate_handle_async
|
10
|
-
|
14
|
+
on_async = callback(:on_async, async_ptr.address)
|
15
|
+
error = check_result(::Libuv::Ext.async_init(loop.handle, async_ptr, on_async))
|
11
16
|
|
12
17
|
super(async_ptr, error)
|
13
18
|
end
|
data/lib/libuv/check.rb
CHANGED
data/lib/libuv/dns.rb
CHANGED
@@ -3,6 +3,9 @@ module Libuv
|
|
3
3
|
include Resource, Listener, Net
|
4
4
|
|
5
5
|
|
6
|
+
define_callback function: :on_complete, params: [:pointer, :int, Ext::UvAddrinfo.by_ref]
|
7
|
+
|
8
|
+
|
6
9
|
attr_reader :results
|
7
10
|
attr_reader :domain
|
8
11
|
attr_reader :port
|
@@ -38,7 +41,9 @@ module Libuv
|
|
38
41
|
@pointer = ::Libuv::Ext.allocate_request_getaddrinfo
|
39
42
|
@error = nil # error in callback
|
40
43
|
|
44
|
+
@instance_id = @pointer.address
|
41
45
|
error = check_result ::Libuv::Ext.getaddrinfo(@loop, @pointer, callback(:on_complete), domain, port.to_s, HINTS[hint])
|
46
|
+
|
42
47
|
if error
|
43
48
|
::Libuv::Ext.free(@pointer)
|
44
49
|
@complete = true
|
@@ -80,7 +85,7 @@ module Libuv
|
|
80
85
|
end
|
81
86
|
|
82
87
|
# Clean up references
|
83
|
-
|
88
|
+
cleanup_callbacks
|
84
89
|
end
|
85
90
|
end
|
86
91
|
end
|
data/lib/libuv/ext/ext.rb
CHANGED
@@ -142,6 +142,7 @@ module Libuv
|
|
142
142
|
attach_function :pipe_pending_count, :uv_pipe_pending_count, [:uv_pipe_t], :int, :blocking => true
|
143
143
|
attach_function :pipe_pending_type, :uv_pipe_pending_type, [:uv_pipe_t], :uv_handle_type, :blocking => true
|
144
144
|
attach_function :pipe_getsockname, :uv_pipe_getsockname, [:uv_pipe_t, :pointer, :pointer], :int, :blocking => true
|
145
|
+
attach_function :pipe_getpeername, :uv_pipe_getpeername, [:uv_pipe_t, :pointer, :pointer], :int, :blocking => true
|
145
146
|
|
146
147
|
attach_function :prepare_init, :uv_prepare_init, [:uv_loop_t, :uv_prepare_t], :int, :blocking => true
|
147
148
|
attach_function :prepare_start, :uv_prepare_start, [:uv_prepare_t, :uv_prepare_cb], :int, :blocking => true
|
data/lib/libuv/ext/tasks.rb
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
file 'ext/libuv/build/gyp' => 'ext/libuv/build' do
|
16
16
|
result = true
|
17
17
|
if not File.directory?('ext/libuv/build/gyp')
|
18
|
-
result = system "
|
18
|
+
result = system "git", "clone", "https://chromium.googlesource.com/external/gyp", "ext/libuv/build/gyp"
|
19
19
|
end
|
20
20
|
raise 'unable to download gyp' unless result
|
21
21
|
end
|
data/lib/libuv/file.rb
CHANGED
@@ -3,6 +3,23 @@ module Libuv
|
|
3
3
|
include Assertions, Resource, Listener, FsChecks
|
4
4
|
|
5
5
|
|
6
|
+
fs_params = {
|
7
|
+
params: [Ext::FsRequest.by_ref],
|
8
|
+
lookup: :fs_lookup
|
9
|
+
}
|
10
|
+
define_callback function: :on_open, **fs_params
|
11
|
+
define_callback function: :on_close, **fs_params
|
12
|
+
define_callback function: :on_read, **fs_params
|
13
|
+
define_callback function: :on_write, **fs_params
|
14
|
+
define_callback function: :on_sync, **fs_params
|
15
|
+
define_callback function: :on_datasync, **fs_params
|
16
|
+
define_callback function: :on_truncate, **fs_params
|
17
|
+
define_callback function: :on_utime, **fs_params
|
18
|
+
define_callback function: :on_chmod, **fs_params
|
19
|
+
define_callback function: :on_chown, **fs_params
|
20
|
+
define_callback function: :on_stat, **fs_params
|
21
|
+
|
22
|
+
|
6
23
|
EOF = "0\r\n\r\n".freeze
|
7
24
|
CRLF = "\r\n".freeze
|
8
25
|
|
@@ -10,8 +27,8 @@ module Libuv
|
|
10
27
|
attr_reader :fileno, :closed
|
11
28
|
|
12
29
|
|
13
|
-
def initialize(
|
14
|
-
super(
|
30
|
+
def initialize(thread, path, flags = 0, mode = 0)
|
31
|
+
super(thread, thread.defer)
|
15
32
|
|
16
33
|
@fileno = -1
|
17
34
|
@closed = true
|
@@ -19,14 +36,14 @@ module Libuv
|
|
19
36
|
@request_refs = {}
|
20
37
|
|
21
38
|
request = ::Libuv::Ext.allocate_request_fs
|
22
|
-
pre_check @defer, request, ::Libuv::Ext.fs_open(@loop, request, @path, @flags, @mode, callback(:on_open))
|
39
|
+
pre_check @defer, request, ::Libuv::Ext.fs_open(@loop, request, @path, @flags, @mode, callback(:on_open, request.address))
|
23
40
|
nil
|
24
41
|
end
|
25
42
|
|
26
43
|
def close
|
27
44
|
@closed = true
|
28
45
|
request = ::Libuv::Ext.allocate_request_fs
|
29
|
-
pre_check(@defer, request, ::Libuv::Ext.fs_close(@loop.handle, request, @fileno, callback(:on_close)))
|
46
|
+
pre_check(@defer, request, ::Libuv::Ext.fs_close(@loop.handle, request, @fileno, callback(:on_close, request.address)))
|
30
47
|
nil # pre-check returns a promise
|
31
48
|
end
|
32
49
|
|
@@ -41,7 +58,7 @@ module Libuv
|
|
41
58
|
|
42
59
|
@request_refs[request.address] = [deferred, buffer1]
|
43
60
|
|
44
|
-
pre_check(deferred, request, ::Libuv::Ext.fs_read(@loop.handle, request, @fileno, buffer, 1, offset, callback(:on_read)))
|
61
|
+
pre_check(deferred, request, ::Libuv::Ext.fs_read(@loop.handle, request, @fileno, buffer, 1, offset, callback(:on_read, request.address)))
|
45
62
|
end
|
46
63
|
|
47
64
|
def write(data, offset = 0)
|
@@ -57,7 +74,7 @@ module Libuv
|
|
57
74
|
|
58
75
|
@request_refs[request.address] = [deferred, buffer1]
|
59
76
|
|
60
|
-
pre_check(deferred, request, ::Libuv::Ext.fs_write(@loop.handle, request, @fileno, buffer, 1, offset, callback(:on_write)))
|
77
|
+
pre_check(deferred, request, ::Libuv::Ext.fs_write(@loop.handle, request, @fileno, buffer, 1, offset, callback(:on_write, request.address)))
|
61
78
|
end
|
62
79
|
|
63
80
|
def sync
|
@@ -66,7 +83,7 @@ module Libuv
|
|
66
83
|
request = ::Libuv::Ext.allocate_request_fs
|
67
84
|
@request_refs[request.address] = deferred
|
68
85
|
|
69
|
-
pre_check deferred, request, ::Libuv::Ext.fs_fsync(@loop.handle, request, @fileno, callback(:on_sync))
|
86
|
+
pre_check deferred, request, ::Libuv::Ext.fs_fsync(@loop.handle, request, @fileno, callback(:on_sync, request.address))
|
70
87
|
end
|
71
88
|
|
72
89
|
def datasync
|
@@ -75,7 +92,7 @@ module Libuv
|
|
75
92
|
request = ::Libuv::Ext.allocate_request_fs
|
76
93
|
@request_refs[request.address] = deferred
|
77
94
|
|
78
|
-
pre_check deferred, request, ::Libuv::Ext.fs_fdatasync(@loop.handle, request, @fileno, callback(:on_datasync))
|
95
|
+
pre_check deferred, request, ::Libuv::Ext.fs_fdatasync(@loop.handle, request, @fileno, callback(:on_datasync, request.address))
|
79
96
|
end
|
80
97
|
|
81
98
|
def truncate(offset)
|
@@ -85,7 +102,7 @@ module Libuv
|
|
85
102
|
request = ::Libuv::Ext.allocate_request_fs
|
86
103
|
@request_refs[request.address] = deferred
|
87
104
|
|
88
|
-
pre_check deferred, request, ::Libuv::Ext.fs_ftruncate(@loop.handle, request, @fileno, offset, callback(:on_truncate))
|
105
|
+
pre_check deferred, request, ::Libuv::Ext.fs_ftruncate(@loop.handle, request, @fileno, offset, callback(:on_truncate, request.address))
|
89
106
|
end
|
90
107
|
|
91
108
|
def utime(atime, mtime)
|
@@ -96,7 +113,7 @@ module Libuv
|
|
96
113
|
request = ::Libuv::Ext.allocate_request_fs
|
97
114
|
@request_refs[request.address] = deferred
|
98
115
|
|
99
|
-
pre_check deferred, request, ::Libuv::Ext.fs_futime(@loop.handle, request, @fileno, atime, mtime, callback(:on_utime))
|
116
|
+
pre_check deferred, request, ::Libuv::Ext.fs_futime(@loop.handle, request, @fileno, atime, mtime, callback(:on_utime, request.address))
|
100
117
|
end
|
101
118
|
|
102
119
|
def chmod(mode)
|
@@ -106,7 +123,7 @@ module Libuv
|
|
106
123
|
request = ::Libuv::Ext.allocate_request_fs
|
107
124
|
@request_refs[request.address] = deferred
|
108
125
|
|
109
|
-
pre_check deferred, request, ::Libuv::Ext.fs_fchmod(@loop.handle, request, @fileno, mode, callback(:on_chmod))
|
126
|
+
pre_check deferred, request, ::Libuv::Ext.fs_fchmod(@loop.handle, request, @fileno, mode, callback(:on_chmod, request.address))
|
110
127
|
end
|
111
128
|
|
112
129
|
def chown(uid, gid)
|
@@ -117,7 +134,7 @@ module Libuv
|
|
117
134
|
request = ::Libuv::Ext.allocate_request_fs
|
118
135
|
@request_refs[request.address] = deferred
|
119
136
|
|
120
|
-
pre_check deferred, request, ::Libuv::Ext.fs_fchown(@loop.handle, request, @fileno, uid, gid, callback(:on_chown))
|
137
|
+
pre_check deferred, request, ::Libuv::Ext.fs_fchown(@loop.handle, request, @fileno, uid, gid, callback(:on_chown, request.address))
|
121
138
|
end
|
122
139
|
|
123
140
|
def send_file(stream, type = :raw, chunk_size = 4096)
|
data/lib/libuv/filesystem.rb
CHANGED
@@ -3,8 +3,26 @@ module Libuv
|
|
3
3
|
include Assertions, Resource, Listener, FsChecks
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
fs_params = {
|
7
|
+
params: [Ext::FsRequest.by_ref],
|
8
|
+
lookup: :fs_lookup
|
9
|
+
}
|
10
|
+
define_callback function: :on_unlink, **fs_params
|
11
|
+
define_callback function: :on_mkdir, **fs_params
|
12
|
+
define_callback function: :on_rmdir, **fs_params
|
13
|
+
define_callback function: :on_readdir, **fs_params
|
14
|
+
define_callback function: :on_rename, **fs_params
|
15
|
+
define_callback function: :on_chmod, **fs_params
|
16
|
+
define_callback function: :on_utime, **fs_params
|
17
|
+
define_callback function: :on_stat, **fs_params
|
18
|
+
define_callback function: :on_link, **fs_params
|
19
|
+
define_callback function: :on_symlink, **fs_params
|
20
|
+
define_callback function: :on_readlink, **fs_params
|
21
|
+
define_callback function: :on_chown, **fs_params
|
22
|
+
|
23
|
+
|
24
|
+
def initialize(thread)
|
25
|
+
@loop = thread
|
8
26
|
end
|
9
27
|
|
10
28
|
def unlink(path)
|
@@ -12,7 +30,7 @@ module Libuv
|
|
12
30
|
@unlink_deferred = @loop.defer
|
13
31
|
|
14
32
|
request = ::Libuv::Ext.allocate_request_fs
|
15
|
-
pre_check @unlink_deferred, request, ::Libuv::Ext.fs_unlink(@loop, request, path, callback(:on_unlink))
|
33
|
+
pre_check @unlink_deferred, request, ::Libuv::Ext.fs_unlink(@loop, request, path, callback(:on_unlink, request.address))
|
16
34
|
@unlink_deferred.promise
|
17
35
|
end
|
18
36
|
|
@@ -22,7 +40,7 @@ module Libuv
|
|
22
40
|
@mkdir_deferred = @loop.defer
|
23
41
|
|
24
42
|
request = ::Libuv::Ext.allocate_request_fs
|
25
|
-
pre_check @mkdir_deferred, request, ::Libuv::Ext.fs_mkdir(@loop, request, path, mode, callback(:on_mkdir))
|
43
|
+
pre_check @mkdir_deferred, request, ::Libuv::Ext.fs_mkdir(@loop, request, path, mode, callback(:on_mkdir, request.address))
|
26
44
|
@mkdir_deferred.promise
|
27
45
|
end
|
28
46
|
|
@@ -31,7 +49,7 @@ module Libuv
|
|
31
49
|
@rmdir_deferred = @loop.defer
|
32
50
|
|
33
51
|
request = ::Libuv::Ext.allocate_request_fs
|
34
|
-
pre_check @rmdir_deferred, request, ::Libuv::Ext.fs_rmdir(@loop, request, path, callback(:on_rmdir))
|
52
|
+
pre_check @rmdir_deferred, request, ::Libuv::Ext.fs_rmdir(@loop, request, path, callback(:on_rmdir, request.address))
|
35
53
|
@rmdir_deferred.promise
|
36
54
|
end
|
37
55
|
|
@@ -40,7 +58,7 @@ module Libuv
|
|
40
58
|
@readdir_deferred = @loop.defer
|
41
59
|
|
42
60
|
request = ::Libuv::Ext.allocate_request_fs
|
43
|
-
pre_check @readdir_deferred, request, ::Libuv::Ext.fs_readdir(@loop, request, path, 0, callback(:on_readdir))
|
61
|
+
pre_check @readdir_deferred, request, ::Libuv::Ext.fs_readdir(@loop, request, path, 0, callback(:on_readdir, request.address))
|
44
62
|
@readdir_deferred.promise
|
45
63
|
end
|
46
64
|
|
@@ -50,7 +68,7 @@ module Libuv
|
|
50
68
|
@rename_deferred = @loop.defer
|
51
69
|
|
52
70
|
request = ::Libuv::Ext.allocate_request_fs
|
53
|
-
pre_check @rename_deferred, request, ::Libuv::Ext.fs_rename(@loop, request, old_path, new_path, callback(:on_rename))
|
71
|
+
pre_check @rename_deferred, request, ::Libuv::Ext.fs_rename(@loop, request, old_path, new_path, callback(:on_rename, request.address))
|
54
72
|
@rename_deferred.promise
|
55
73
|
end
|
56
74
|
|
@@ -60,7 +78,7 @@ module Libuv
|
|
60
78
|
@chmod_deferred = @loop.defer
|
61
79
|
|
62
80
|
request = ::Libuv::Ext.allocate_request_fs
|
63
|
-
pre_check @chmod_deferred, request, ::Libuv::Ext.fs_chmod(@loop, request, path, mode, callback(:on_chmod))
|
81
|
+
pre_check @chmod_deferred, request, ::Libuv::Ext.fs_chmod(@loop, request, path, mode, callback(:on_chmod, request.address))
|
64
82
|
@chmod_deferred.promise
|
65
83
|
end
|
66
84
|
|
@@ -71,7 +89,7 @@ module Libuv
|
|
71
89
|
@utime_deferred = @loop.defer
|
72
90
|
|
73
91
|
request = ::Libuv::Ext.allocate_request_fs
|
74
|
-
pre_check @utime_deferred, request, ::Libuv::Ext.fs_utime(@loop, request, path, atime, mtime, callback(:on_utime))
|
92
|
+
pre_check @utime_deferred, request, ::Libuv::Ext.fs_utime(@loop, request, path, atime, mtime, callback(:on_utime, request.address))
|
75
93
|
@utime_deferred.promise
|
76
94
|
end
|
77
95
|
|
@@ -80,7 +98,7 @@ module Libuv
|
|
80
98
|
@stat_deferred = @loop.defer
|
81
99
|
|
82
100
|
request = ::Libuv::Ext.allocate_request_fs
|
83
|
-
pre_check @stat_deferred, request, ::Libuv::Ext.fs_lstat(@loop, request, path, callback(:on_stat))
|
101
|
+
pre_check @stat_deferred, request, ::Libuv::Ext.fs_lstat(@loop, request, path, callback(:on_stat, request.address))
|
84
102
|
@stat_deferred.promise
|
85
103
|
end
|
86
104
|
|
@@ -90,7 +108,7 @@ module Libuv
|
|
90
108
|
@link_deferred = @loop.defer
|
91
109
|
|
92
110
|
request = ::Libuv::Ext.allocate_request_fs
|
93
|
-
pre_check @link_deferred, request, ::Libuv::Ext.fs_link(@loop, request, old_path, new_path, callback(:on_link))
|
111
|
+
pre_check @link_deferred, request, ::Libuv::Ext.fs_link(@loop, request, old_path, new_path, callback(:on_link, request.address))
|
94
112
|
@link_deferred.promise
|
95
113
|
end
|
96
114
|
|
@@ -100,7 +118,7 @@ module Libuv
|
|
100
118
|
@symlink_deferred = @loop.defer
|
101
119
|
|
102
120
|
request = ::Libuv::Ext.allocate_request_fs
|
103
|
-
pre_check @symlink_deferred, request, ::Libuv::Ext.fs_symlink(@loop, request, old_path, new_path, 0, callback(:on_symlink))
|
121
|
+
pre_check @symlink_deferred, request, ::Libuv::Ext.fs_symlink(@loop, request, old_path, new_path, 0, callback(:on_symlink, request.address))
|
104
122
|
@symlink_deferred.promise
|
105
123
|
end
|
106
124
|
|
@@ -109,7 +127,7 @@ module Libuv
|
|
109
127
|
@readlink_deferred = @loop.defer
|
110
128
|
|
111
129
|
request = ::Libuv::Ext.allocate_request_fs
|
112
|
-
pre_check @readlink_deferred, request, ::Libuv::Ext.fs_readlink(@loop, request, path, callback(:on_readlink))
|
130
|
+
pre_check @readlink_deferred, request, ::Libuv::Ext.fs_readlink(@loop, request, path, callback(:on_readlink, request.address))
|
113
131
|
@readlink_deferred.promise
|
114
132
|
end
|
115
133
|
|
@@ -120,7 +138,7 @@ module Libuv
|
|
120
138
|
@chown_deferred = @loop.defer
|
121
139
|
|
122
140
|
request = ::Libuv::Ext.allocate_request_fs
|
123
|
-
pre_check @chown_deferred, request, ::Libuv::Ext.fs_chown(@loop, request, path, uid, gid, callback(:on_chown))
|
141
|
+
pre_check @chown_deferred, request, ::Libuv::Ext.fs_chown(@loop, request, path, uid, gid, callback(:on_chown, request.address))
|
124
142
|
@chown_deferred.promise
|
125
143
|
end
|
126
144
|
|
data/lib/libuv/fs_event.rb
CHANGED
@@ -2,14 +2,17 @@ module Libuv
|
|
2
2
|
class FSEvent < Handle
|
3
3
|
|
4
4
|
|
5
|
+
define_callback function: :on_fs_event, params: [:pointer, :string, :int, :int]
|
6
|
+
|
7
|
+
|
5
8
|
EVENTS = {1 => :rename, 2 => :change}.freeze
|
6
9
|
|
7
10
|
|
8
|
-
def initialize(
|
9
|
-
@loop =
|
11
|
+
def initialize(thread, path)
|
12
|
+
@loop = thread
|
10
13
|
|
11
14
|
fs_event_ptr = ::Libuv::Ext.allocate_handle_fs_event
|
12
|
-
error = check_result ::Libuv::Ext.fs_event_init(
|
15
|
+
error = check_result ::Libuv::Ext.fs_event_init(thread.handle, fs_event_ptr, path, callback(:on_fs_event, fs_event_ptr.address), 0)
|
13
16
|
|
14
17
|
super(fs_event_ptr, error)
|
15
18
|
end
|
data/lib/libuv/handle.rb
CHANGED
@@ -8,8 +8,12 @@ module Libuv
|
|
8
8
|
attr_reader :loop
|
9
9
|
|
10
10
|
|
11
|
+
define_callback function: :on_close
|
12
|
+
|
13
|
+
|
11
14
|
def initialize(pointer, error)
|
12
15
|
@pointer = pointer
|
16
|
+
@instance_id = @pointer.address
|
13
17
|
|
14
18
|
# Initialise the promise
|
15
19
|
super(loop, loop.defer)
|
@@ -61,6 +65,7 @@ module Libuv
|
|
61
65
|
|
62
66
|
def handle; @pointer; end
|
63
67
|
def defer; @defer; end
|
68
|
+
def instance_id; @instance_id; end
|
64
69
|
|
65
70
|
|
66
71
|
private
|
@@ -74,7 +79,8 @@ module Libuv
|
|
74
79
|
|
75
80
|
def on_close(pointer)
|
76
81
|
::Libuv::Ext.free(pointer)
|
77
|
-
clear_callbacks
|
82
|
+
#clear_callbacks
|
83
|
+
cleanup_callbacks
|
78
84
|
|
79
85
|
if @close_error
|
80
86
|
defer.reject(@close_error)
|
data/lib/libuv/idle.rb
CHANGED
@@ -2,14 +2,17 @@ module Libuv
|
|
2
2
|
class Idle < Handle
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
define_callback function: :on_idle
|
6
|
+
|
7
|
+
|
8
|
+
# @param thread [::Libuv::Loop] loop this idle handler will be associated
|
6
9
|
# @param callback [Proc] callback to be called when the loop is idle
|
7
|
-
def initialize(
|
8
|
-
@loop =
|
10
|
+
def initialize(thread, callback = nil, &blk)
|
11
|
+
@loop = thread
|
9
12
|
@callback = callback || blk
|
10
13
|
|
11
14
|
idle_ptr = ::Libuv::Ext.allocate_handle_idle
|
12
|
-
error = check_result(::Libuv::Ext.idle_init(
|
15
|
+
error = check_result(::Libuv::Ext.idle_init(thread.handle, idle_ptr))
|
13
16
|
|
14
17
|
super(idle_ptr, error)
|
15
18
|
end
|
@@ -3,11 +3,22 @@ module Libuv
|
|
3
3
|
module FsChecks
|
4
4
|
|
5
5
|
|
6
|
+
module ClassMethods
|
7
|
+
def fs_lookup(ref)
|
8
|
+
ref.to_ptr.address
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
|
6
17
|
def stat
|
7
18
|
@stat_deferred = @loop.defer
|
8
19
|
|
9
20
|
request = ::Libuv::Ext.allocate_request_fs
|
10
|
-
pre_check @stat_deferred, request, ::Libuv::Ext.fs_fstat(@loop.handle, request, @fileno, callback(:on_stat))
|
21
|
+
pre_check @stat_deferred, request, ::Libuv::Ext.fs_fstat(@loop.handle, request, @fileno, callback(:on_stat, request.address))
|
11
22
|
@stat_deferred.promise
|
12
23
|
end
|
13
24
|
|
@@ -42,6 +53,8 @@ module Libuv
|
|
42
53
|
end
|
43
54
|
|
44
55
|
def cleanup(req)
|
56
|
+
cleanup_callbacks req.to_ptr.address
|
57
|
+
|
45
58
|
::Libuv::Ext.fs_req_cleanup(req)
|
46
59
|
::Libuv::Ext.free(req)
|
47
60
|
end
|
@@ -8,27 +8,59 @@ module Libuv
|
|
8
8
|
private
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
module ClassMethods
|
12
|
+
def dispatch_callback(func_name, lookup, args)
|
13
|
+
instance_id = __send__(lookup, *args)
|
14
|
+
inst = @callback_lookup[instance_id]
|
15
|
+
inst.__send__(func_name, *args)
|
16
|
+
end
|
12
17
|
|
18
|
+
def define_callback(function:, params: [:pointer], ret_val: :void, lookup: :default_lookup)
|
19
|
+
@callback_funcs[function] = FFI::Function.new(ret_val, params) do |*args|
|
20
|
+
dispatch_callback(function, lookup, args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Much like include to support inheritance properly
|
25
|
+
# We keep existing callbacks and inherit the lookup (as this will never clash)
|
26
|
+
def inherited(subclass)
|
27
|
+
subclass.instance_variable_set(:@callback_funcs, {}.merge(@callback_funcs))
|
28
|
+
subclass.instance_variable_set(:@callback_lookup, @callback_lookup)
|
29
|
+
end
|
13
30
|
|
14
|
-
def callbacks
|
15
|
-
@callbacks ||= Set.new
|
16
|
-
end
|
17
31
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
callbacks << const_name
|
22
|
-
CALLBACKS[const_name] = method(name)
|
32
|
+
# Provide accessor methods to the class level instance variables
|
33
|
+
def callback_lookup
|
34
|
+
@callback_lookup
|
23
35
|
end
|
24
|
-
CALLBACKS[const_name]
|
25
|
-
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
def callback_funcs
|
38
|
+
@callback_funcs
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# This function is used to work out the instance the callback is for
|
43
|
+
def default_lookup(req, *args)
|
44
|
+
req.address
|
30
45
|
end
|
31
|
-
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.included(base)
|
49
|
+
base.instance_variable_set(:@callback_funcs, {})
|
50
|
+
base.instance_variable_set(:@callback_lookup, ThreadSafe::Cache.new)
|
51
|
+
base.extend(ClassMethods)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
def callback(name, instance_id = @instance_id)
|
57
|
+
klass = self.class
|
58
|
+
klass.callback_lookup[instance_id] ||= self
|
59
|
+
klass.callback_funcs[name]
|
60
|
+
end
|
61
|
+
|
62
|
+
def cleanup_callbacks(instance_id = @instance_id)
|
63
|
+
self.class.callback_lookup.delete(instance_id)
|
32
64
|
end
|
33
65
|
end
|
34
66
|
end
|
data/lib/libuv/mixins/stream.rb
CHANGED
@@ -2,6 +2,17 @@ module Libuv
|
|
2
2
|
module Stream
|
3
3
|
|
4
4
|
|
5
|
+
def self.included(base)
|
6
|
+
base.define_callback function: :on_listen, params: [:pointer, :int]
|
7
|
+
base.define_callback function: :write_complete, params: [:pointer, :int]
|
8
|
+
base.define_callback function: :on_shutdown, params: [:pointer, :int]
|
9
|
+
|
10
|
+
base.define_callback function: :on_allocate, params: [:pointer, :size_t, Ext::UvBuf.by_ref]
|
11
|
+
base.define_callback function: :on_read, params: [:pointer, :ssize_t, Ext::UvBuf.by_ref]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
5
16
|
BACKLOG_ERROR = "backlog must be an Integer".freeze
|
6
17
|
WRITE_ERROR = "data must be a String".freeze
|
7
18
|
STREAM_CLOSED_ERROR = "unable to write to a closed stream".freeze
|
@@ -64,10 +75,12 @@ module Libuv
|
|
64
75
|
@write_callbacks ||= {}
|
65
76
|
req = ::Libuv::Ext.allocate_request_write
|
66
77
|
@write_callbacks[req.address] = [deferred, buffer1]
|
67
|
-
error = check_result ::Libuv::Ext.write(req, handle, buffer, 1, callback(:write_complete))
|
78
|
+
error = check_result ::Libuv::Ext.write(req, handle, buffer, 1, callback(:write_complete, req.address))
|
68
79
|
|
69
80
|
if error
|
70
81
|
@write_callbacks.delete req.address
|
82
|
+
cleanup_callbacks req.address
|
83
|
+
|
71
84
|
::Libuv::Ext.free(req)
|
72
85
|
buffer1.free
|
73
86
|
deferred.reject(error)
|
@@ -122,6 +135,7 @@ module Libuv
|
|
122
135
|
|
123
136
|
def write_complete(req, status)
|
124
137
|
deferred, buffer1 = @write_callbacks.delete req.address
|
138
|
+
cleanup_callbacks req.address
|
125
139
|
|
126
140
|
::Libuv::Ext.free(req)
|
127
141
|
buffer1.free
|
data/lib/libuv/pipe.rb
CHANGED
@@ -3,6 +3,10 @@ module Libuv
|
|
3
3
|
include Stream
|
4
4
|
|
5
5
|
|
6
|
+
define_callback function: :on_connect, params: [:pointer, :int]
|
7
|
+
define_callback function: :write2_complete, params: [:pointer, :int]
|
8
|
+
|
9
|
+
|
6
10
|
WRITE2_ERROR = "data must be a String".freeze
|
7
11
|
|
8
12
|
|
@@ -68,7 +72,8 @@ module Libuv
|
|
68
72
|
assert_type(String, name, "name must be a String")
|
69
73
|
begin
|
70
74
|
name = windows_path name if FFI::Platform.windows?
|
71
|
-
::Libuv::Ext.
|
75
|
+
req = ::Libuv::Ext.allocate_request_connect
|
76
|
+
::Libuv::Ext.pipe_connect(req, handle, name, callback(:on_connect, req.address))
|
72
77
|
rescue Exception => e
|
73
78
|
reject(e)
|
74
79
|
end
|
@@ -85,26 +90,13 @@ module Libuv
|
|
85
90
|
buffer = ::Libuv::Ext.buf_init(FFI::MemoryPointer.from_string(data), size)
|
86
91
|
|
87
92
|
# local as this variable will be avaliable until the handle is closed
|
88
|
-
@write_callbacks = @write_callbacks || []
|
89
|
-
|
90
|
-
#
|
91
|
-
# create the curried callback
|
92
|
-
#
|
93
|
-
callback = FFI::Function.new(:void, [:pointer, :int]) do |req, status|
|
94
|
-
::Libuv::Ext.free(req)
|
95
|
-
# remove the callback from the array
|
96
|
-
# assumes writes are done in order
|
97
|
-
promise = @write_callbacks.shift[0]
|
98
|
-
resolve promise, status
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
@write_callbacks << [deferred, callback]
|
103
93
|
req = ::Libuv::Ext.allocate_request_write
|
104
|
-
|
94
|
+
@write_callbacks ||= {}
|
95
|
+
@write_callbacks[req.address] = deferred
|
96
|
+
error = check_result ::Libuv::Ext.write2(req, handle, buffer, 1, fd.handle, callback(:write2_complete, req.address))
|
105
97
|
|
106
98
|
if error
|
107
|
-
@write_callbacks.
|
99
|
+
@write_callbacks.delete(req.address)
|
108
100
|
::Libuv::Ext.free(req)
|
109
101
|
deferred.reject(error)
|
110
102
|
|
@@ -159,6 +151,7 @@ module Libuv
|
|
159
151
|
|
160
152
|
|
161
153
|
def on_connect(req, status)
|
154
|
+
cleanup_callbacks req.address
|
162
155
|
::Libuv::Ext.free(req)
|
163
156
|
e = check_result(status)
|
164
157
|
|
@@ -173,6 +166,15 @@ module Libuv
|
|
173
166
|
end
|
174
167
|
end
|
175
168
|
|
169
|
+
def write2_complete(req, status)
|
170
|
+
promise = @write_callbacks.delete(req.address)
|
171
|
+
cleanup_callbacks req.address
|
172
|
+
|
173
|
+
::Libuv::Ext.free(req)
|
174
|
+
|
175
|
+
resolve promise, status
|
176
|
+
end
|
177
|
+
|
176
178
|
def windows_path(name)
|
177
179
|
# test for \\\\.\\pipe
|
178
180
|
if not name =~ /(\/|\\){2}\.(\/|\\)pipe/i
|
data/lib/libuv/prepare.rb
CHANGED
@@ -2,6 +2,9 @@ module Libuv
|
|
2
2
|
class Prepare < Handle
|
3
3
|
|
4
4
|
|
5
|
+
define_callback function: :on_prepare
|
6
|
+
|
7
|
+
|
5
8
|
# @param loop [::Libuv::Loop] loop this prepare handle will be associated
|
6
9
|
# @param callback [Proc] callback to be called on loop preparation
|
7
10
|
def initialize(loop, callback = nil, &blk)
|
data/lib/libuv/signal.rb
CHANGED
data/lib/libuv/tcp.rb
CHANGED
@@ -7,10 +7,15 @@ module Libuv
|
|
7
7
|
include Stream, Net
|
8
8
|
|
9
9
|
|
10
|
+
define_callback function: :on_connect, params: [:pointer, :int]
|
11
|
+
|
12
|
+
|
10
13
|
TLS_ERROR = "TLS write failed".freeze
|
11
14
|
|
12
15
|
|
13
16
|
attr_reader :connected
|
17
|
+
attr_reader :protocol
|
18
|
+
|
14
19
|
# Check if tls active on the socket
|
15
20
|
def tls?; !@tls.nil?; end
|
16
21
|
|
@@ -48,14 +53,27 @@ module Libuv
|
|
48
53
|
end
|
49
54
|
|
50
55
|
# Push through any pending writes when handshake has completed
|
51
|
-
def handshake_cb
|
56
|
+
def handshake_cb(protocol = nil)
|
52
57
|
@handshake = true
|
58
|
+
@protocol = protocol
|
59
|
+
|
53
60
|
writes = @pending_writes
|
54
61
|
@pending_writes = nil
|
55
62
|
writes.each do |deferred, data|
|
56
63
|
@pending_write = deferred
|
57
64
|
@tls.encrypt(data)
|
58
65
|
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
@on_handshake.call(self, protocol) if @on_handshake
|
69
|
+
rescue => e
|
70
|
+
@loop.log :warn, :tls_handshake_callback_error, e
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Provide a callback once the TLS handshake has completed
|
75
|
+
def on_handshake(callback = nil, &blk)
|
76
|
+
@on_handshake = callback || blk
|
59
77
|
end
|
60
78
|
|
61
79
|
# This is clear text data that has been decrypted
|
@@ -211,7 +229,7 @@ module Libuv
|
|
211
229
|
|
212
230
|
begin
|
213
231
|
@tcp_socket = create_socket(IPAddr.new(ip), port)
|
214
|
-
@tcp_socket.connect(callback(:on_connect))
|
232
|
+
@tcp_socket.connect(callback(:on_connect, @tcp_socket.connect_req.address))
|
215
233
|
rescue Exception => e
|
216
234
|
reject(e)
|
217
235
|
end
|
@@ -274,6 +292,7 @@ module Libuv
|
|
274
292
|
end
|
275
293
|
|
276
294
|
def on_connect(req, status)
|
295
|
+
cleanup_callbacks req.address
|
277
296
|
::Libuv::Ext.free(req)
|
278
297
|
e = check_result(status)
|
279
298
|
|
@@ -307,13 +326,14 @@ module Libuv
|
|
307
326
|
check_result!(tcp_connect(callback))
|
308
327
|
end
|
309
328
|
|
329
|
+
def connect_req
|
330
|
+
@req ||= ::Libuv::Ext.allocate_request_connect
|
331
|
+
@req
|
332
|
+
end
|
310
333
|
|
311
|
-
protected
|
312
334
|
|
335
|
+
protected
|
313
336
|
|
314
|
-
def connect_req
|
315
|
-
::Libuv::Ext.allocate_request_connect
|
316
|
-
end
|
317
337
|
|
318
338
|
def tcp_connect(callback)
|
319
339
|
::Libuv::Ext.tcp_connect(
|
data/lib/libuv/timer.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Libuv
|
2
2
|
class Timer < Handle
|
3
3
|
|
4
|
+
|
5
|
+
define_callback function: :on_timer
|
6
|
+
|
7
|
+
|
4
8
|
# @param loop [::Libuv::Loop] loop this timer will be associated
|
5
9
|
# @param callback [Proc] callback to be called when the timer is triggered
|
6
10
|
def initialize(loop, callback = nil)
|
data/lib/libuv/udp.rb
CHANGED
@@ -3,6 +3,11 @@ module Libuv
|
|
3
3
|
include Net
|
4
4
|
|
5
5
|
|
6
|
+
define_callback function: :on_allocate, params: [:pointer, :size_t, Ext::UvBuf.by_ref]
|
7
|
+
define_callback function: :on_recv, params: [:pointer, :ssize_t, Ext::UvBuf.by_ref, Ext::Sockaddr.by_ref, :uint]
|
8
|
+
define_callback function: :send_complete, params: [:pointer, :int]
|
9
|
+
|
10
|
+
|
6
11
|
SEND_DATA_ERROR = "data must be a String".freeze
|
7
12
|
TTL_ARGUMENT_ERROR = "ttl must be an Integer".freeze
|
8
13
|
MULTICAST_ARGUMENT_ERROR = "multicast_address must be a String".freeze
|
@@ -124,10 +129,11 @@ module Libuv
|
|
124
129
|
buffer,
|
125
130
|
1,
|
126
131
|
sockaddr,
|
127
|
-
callback(:send_complete)
|
132
|
+
callback(:send_complete, req.address)
|
128
133
|
)
|
129
134
|
if error
|
130
135
|
@request_refs.delete req.address
|
136
|
+
cleanup_callbacks req.address
|
131
137
|
::Libuv::Ext.free(req)
|
132
138
|
buffer1.free
|
133
139
|
deferred.reject(error)
|
@@ -251,6 +257,7 @@ module Libuv
|
|
251
257
|
|
252
258
|
def send_complete(req, status)
|
253
259
|
deferred, buffer1 = @request_refs.delete req.address
|
260
|
+
cleanup_callbacks req.address
|
254
261
|
|
255
262
|
::Libuv::Ext.free(req)
|
256
263
|
buffer1.free
|
data/lib/libuv/version.rb
CHANGED
data/lib/libuv/work.rb
CHANGED
@@ -7,16 +7,22 @@ module Libuv
|
|
7
7
|
attr_reader :result
|
8
8
|
|
9
9
|
|
10
|
-
|
10
|
+
define_callback function: :on_work
|
11
|
+
define_callback function: :on_complete, params: [:pointer, :int]
|
12
|
+
|
13
|
+
|
14
|
+
# @param thread [::Libuv::Loop] thread this work request will be associated
|
11
15
|
# @param work [Proc] callback to be called in the thread pool
|
12
|
-
def initialize(
|
13
|
-
super(
|
16
|
+
def initialize(thread, work)
|
17
|
+
super(thread, thread.defer)
|
14
18
|
|
15
19
|
@work = work
|
16
20
|
@complete = false
|
17
21
|
@pointer = ::Libuv::Ext.allocate_request_work
|
18
22
|
@error = nil # error in callback
|
19
23
|
|
24
|
+
@instance_id = @pointer.address
|
25
|
+
|
20
26
|
error = check_result ::Libuv::Ext.queue_work(@loop, @pointer, callback(:on_work), callback(:on_complete))
|
21
27
|
if error
|
22
28
|
::Libuv::Ext.free(@pointer)
|
@@ -62,7 +68,7 @@ module Libuv
|
|
62
68
|
end
|
63
69
|
|
64
70
|
# Clean up references
|
65
|
-
|
71
|
+
cleanup_callbacks @instance_id
|
66
72
|
end
|
67
73
|
|
68
74
|
def on_work(req)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libuv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bulat Shakirzyanov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- ext/libuv/docs/src/process.rst
|
153
153
|
- ext/libuv/docs/src/request.rst
|
154
154
|
- ext/libuv/docs/src/signal.rst
|
155
|
+
- ext/libuv/docs/src/sphinx-plugins/manpage.py
|
155
156
|
- ext/libuv/docs/src/static/architecture.png
|
156
157
|
- ext/libuv/docs/src/static/diagrams.key/Data/st0-311.jpg
|
157
158
|
- ext/libuv/docs/src/static/diagrams.key/Data/st1-475.jpg
|
@@ -367,6 +368,7 @@ files:
|
|
367
368
|
- ext/libuv/test/test-pipe-getsockname.c
|
368
369
|
- ext/libuv/test/test-pipe-sendmsg.c
|
369
370
|
- ext/libuv/test/test-pipe-server-close.c
|
371
|
+
- ext/libuv/test/test-pipe-set-non-blocking.c
|
370
372
|
- ext/libuv/test/test-platform-output.c
|
371
373
|
- ext/libuv/test/test-poll-close-doesnt-corrupt-stack.c
|
372
374
|
- ext/libuv/test/test-poll-close.c
|
@@ -395,6 +397,7 @@ files:
|
|
395
397
|
- ext/libuv/test/test-tcp-connect-timeout.c
|
396
398
|
- ext/libuv/test/test-tcp-connect6-error.c
|
397
399
|
- ext/libuv/test/test-tcp-flags.c
|
400
|
+
- ext/libuv/test/test-tcp-oob.c
|
398
401
|
- ext/libuv/test/test-tcp-open.c
|
399
402
|
- ext/libuv/test/test-tcp-read-stop.c
|
400
403
|
- ext/libuv/test/test-tcp-shutdown-after-write.c
|