uvrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,24 @@
1
+ module UV
2
+ module Assertions
3
+ def assert_block(proc, msg = "no block given")
4
+ raise ArgumentError, msg, caller if proc.nil?
5
+ end
6
+
7
+ def assert_arity(expected, proc, msg = nil)
8
+ actual = proc.arity
9
+ arg = expected == 1 ? "argument" : "arguments"
10
+ msg ||= "block must accept #{expected} #{arg}, but accepts #{actual}"
11
+ raise ArgumentError, msg, caller if expected != actual
12
+ end
13
+
14
+ def assert_type(type, actual, msg = nil)
15
+ msg ||= "value #{actual.inspect} is not a valid #{type}"
16
+ raise ArgumentError, msg, caller unless actual.kind_of?(type)
17
+ end
18
+
19
+ def assert_boolean(actual, msg = nil)
20
+ msg ||= "value #{actual.inspect} is not a valid Boolean"
21
+ raise ArgumentError, msg, caller unless actual.kind_of?(TrueClass) || actual.kind_of?(FalseClass)
22
+ end
23
+ end
24
+ end
data/lib/uv/async.rb ADDED
@@ -0,0 +1,24 @@
1
+ module UV
2
+ class Async
3
+ include Handle
4
+
5
+ def initialize(loop, async_ptr, &block)
6
+ @async_block = block
7
+
8
+ super(loop, async_ptr)
9
+ end
10
+
11
+ def call
12
+ check_result UV.async_send(handle)
13
+
14
+ self
15
+ end
16
+
17
+ private
18
+ def on_async(handle, status)
19
+ @async_block.call(check_result(status))
20
+ end
21
+
22
+ public :callback
23
+ end
24
+ end
data/lib/uv/check.rb ADDED
@@ -0,0 +1,27 @@
1
+ module UV
2
+ class Check
3
+ include Handle
4
+
5
+ def start(&block)
6
+ assert_block(block)
7
+ assert_arity(1, block)
8
+
9
+ @check_block = block
10
+
11
+ check_result! UV.check_start(handle, callback(:on_check))
12
+
13
+ self
14
+ end
15
+
16
+ def stop
17
+ check_result! UV.check_stop(handle)
18
+
19
+ self
20
+ end
21
+
22
+ private
23
+ def on_check(handle, status)
24
+ @check_block.call(check_result(status))
25
+ end
26
+ end
27
+ end
data/lib/uv/error.rb ADDED
@@ -0,0 +1,58 @@
1
+ module UV
2
+ class Error < StandardError
3
+ class UNKNOWN < Error; end
4
+ class OK < Error; end
5
+ class EOF < Error; end
6
+ class EADDRINFO < Error; end
7
+ class EACCES < Error; end
8
+ class EAGAIN < Error; end
9
+ class EADDRINUSE < Error; end
10
+ class EADDRNOTAVAIL < Error; end
11
+ class EAFNOSUPPORT < Error; end
12
+ class EALREADY < Error; end
13
+ class EBADF < Error; end
14
+ class EBUSY < Error; end
15
+ class ECONNABORTED < Error; end
16
+ class ECONNREFUSED < Error; end
17
+ class ECONNRESET < Error; end
18
+ class EDESTADDRREQ < Error; end
19
+ class EFAULT < Error; end
20
+ class EHOSTUNREACH < Error; end
21
+ class EINTR < Error; end
22
+ class EINVAL < Error; end
23
+ class EISCONN < Error; end
24
+ class EMFILE < Error; end
25
+ class EMSGSIZE < Error; end
26
+ class ENETDOWN < Error; end
27
+ class ENETUNREACH < Error; end
28
+ class ENFILE < Error; end
29
+ class ENOBUFS < Error; end
30
+ class ENOMEM < Error; end
31
+ class ENOTDIR < Error; end
32
+ class EISDIR < Error; end
33
+ class ENONET < Error; end
34
+ class ENOTCONN < Error; end
35
+ class ENOTSOCK < Error; end
36
+ class ENOTSUP < Error; end
37
+ class ENOENT < Error; end
38
+ class ENOSYS < Error; end
39
+ class EPIPE < Error; end
40
+ class EPROTO < Error; end
41
+ class EPROTONOSUPPORT < Error; end
42
+ class EPROTOTYPE < Error; end
43
+ class ETIMEDOUT < Error; end
44
+ class ECHARSE < Error; end
45
+ class EAIFAMNOSUPPORT < Error; end
46
+ class EAISERVICE < Error; end
47
+ class EAISOCKTYPE < Error; end
48
+ class ESHUTDOWN < Error; end
49
+ class EEXIST < Error; end
50
+ class ESRCH < Error; end
51
+ class ENAMETOOLONG < Error; end
52
+ class EPERM < Error; end
53
+ class ELOOP < Error; end
54
+ class EXDEV < Error; end
55
+ class ENOTEMPTY < Error; end
56
+ class ENOSPC < Error; end
57
+ end
58
+ end
data/lib/uv/file.rb ADDED
@@ -0,0 +1,221 @@
1
+ module UV
2
+ class File
3
+ include Assertions, Resource, Listener
4
+
5
+ def initialize(loop, fd)
6
+ @loop = loop
7
+ @fd = Integer(fd)
8
+ end
9
+
10
+ def close(&block)
11
+ assert_block(block)
12
+ assert_arity(1, block)
13
+
14
+ @close_block = block
15
+
16
+ check_result! UV.fs_close(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_close))
17
+
18
+ self
19
+ end
20
+
21
+ def read(length, offset = 0, &block)
22
+ assert_block(block)
23
+ assert_arity(2, block)
24
+ assert_type(Integer, length, "length must be an Integer")
25
+ assert_type(Integer, offset, "offset must be an Integer")
26
+
27
+ @read_block = block
28
+ @read_buffer_length = length
29
+ @read_buffer = FFI::MemoryPointer.new(@read_buffer_length)
30
+
31
+ check_result! UV.fs_read(loop.to_ptr, UV.create_request(:uv_fs), @fd, @read_buffer, @read_buffer_length, offset, callback(:on_read))
32
+
33
+ self
34
+ end
35
+
36
+ def write(data, offset = 0, &block)
37
+ assert_block(block)
38
+ assert_arity(1, block)
39
+ assert_type(String, data, "data must be a String")
40
+ assert_type(Integer, offset, "offset must be an Integer")
41
+
42
+ @write_block = block
43
+ @write_buffer_length = data.respond_to?(:bytesize) ? data.bytesize : data.size
44
+ @write_buffer = FFI::MemoryPointer.from_string(data)
45
+
46
+ check_result! UV.fs_write(loop.to_ptr, UV.create_request(:uv_fs), @fd, @write_buffer, @write_buffer_length, offset, callback(:on_write))
47
+
48
+ self
49
+ end
50
+
51
+ def stat(&block)
52
+ assert_block(block)
53
+ assert_arity(2, block)
54
+
55
+ @stat_block = block
56
+
57
+ check_result! UV.fs_fstat(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_stat))
58
+
59
+ self
60
+ end
61
+
62
+ def sync(&block)
63
+ assert_block(block)
64
+ assert_arity(1, block)
65
+
66
+ @sync_block = block
67
+
68
+ check_result! UV.fs_fsync(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_sync))
69
+
70
+ self
71
+ end
72
+
73
+ def datasync(&block)
74
+ assert_block(block)
75
+ assert_arity(1, block)
76
+
77
+ @datasync_block = block
78
+
79
+ check_result! UV.fs_fdatasync(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_datasync))
80
+
81
+ self
82
+ end
83
+
84
+ def truncate(offset, &block)
85
+ assert_block(block)
86
+ assert_arity(1, block)
87
+ assert_type(Integer, offset, "offset must be an Integer")
88
+
89
+ @truncate_block = block
90
+
91
+ check_result! UV.fs_ftruncate(loop.to_ptr, UV.create_request(:uv_fs), @fd, offset, callback(:on_truncate))
92
+
93
+ self
94
+ end
95
+
96
+ def utime(atime, mtime, &block)
97
+ assert_block(block)
98
+ assert_arity(1, block)
99
+ assert_type(Integer, atime, "atime must be an Integer")
100
+ assert_type(Integer, mtime, "mtime must be an Integer")
101
+
102
+ @utime_block = block
103
+
104
+ check_result! UV.fs_futime(loop.to_ptr, UV.create_request(:uv_fs), @fd, atime, mtime, callback(:on_utime))
105
+
106
+ self
107
+ end
108
+
109
+ def chmod(mode, &block)
110
+ assert_block(block)
111
+ assert_arity(1, block)
112
+ assert_type(Integer, mode, "mode must be an Integer")
113
+
114
+ @chmod_block = block
115
+
116
+ check_result! UV.fs_fchmod(loop.to_ptr, UV.create_request(:uv_fs), @fd, mode, callback(:on_chmod))
117
+
118
+ self
119
+ end
120
+
121
+ def chown(uid, gid, &block)
122
+ assert_block(block)
123
+ assert_arity(1, block)
124
+ assert_type(Integer, uid, "uid must be an Integer")
125
+ assert_type(Integer, gid, "gid must be an Integer")
126
+
127
+ @chown_block = block
128
+
129
+ check_result! UV.fs_fchown(loop.to_ptr, UV.create_request(:uv_fs), @fd, uid, gid, callback(:on_chown))
130
+
131
+ self
132
+ end
133
+
134
+ private
135
+
136
+ def on_close(req)
137
+ e = check_result(UV.fs_req_result(req))
138
+ UV.fs_req_cleanup(req)
139
+ UV.free(req)
140
+ @close_block.call(e) if @close_block
141
+ end
142
+
143
+ def on_read(req)
144
+ e = check_result(UV.fs_req_result(req))
145
+ unless e
146
+ data = @read_buffer.read_string(@read_buffer_length)
147
+ end
148
+ UV.fs_req_cleanup(req)
149
+ UV.free(req)
150
+ @read_buffer = nil
151
+ @read_buffer_length = nil
152
+ @read_block.call(e, data)
153
+ end
154
+
155
+ def on_write(req)
156
+ e = check_result(UV.fs_req_result(req))
157
+ UV.fs_req_cleanup(req)
158
+ UV.free(req)
159
+ @write_buffer = nil
160
+ @write_buffer_length = nil
161
+ @write_block.call(e) if @write_block
162
+ end
163
+
164
+ def on_stat(req)
165
+ e = check_result(UV.fs_req_result(req))
166
+ unless e
167
+ uv_stat = UV.fs_req_stat(req)
168
+ uv_members = uv_stat.members
169
+
170
+ values = Stat.members.map { |k| uv_members.include?(k) ? uv_stat[k] : nil }
171
+
172
+ stat = Stat.new(*values)
173
+ end
174
+ UV.fs_req_cleanup(req)
175
+ UV.free(req)
176
+ @stat_block.call(e, stat)
177
+ end
178
+
179
+ def on_sync(req)
180
+ e = check_result(UV.fs_req_result(req))
181
+ UV.fs_req_cleanup(req)
182
+ UV.free(req)
183
+ @sync_block.call(e)
184
+ end
185
+
186
+ def on_datasync(req)
187
+ e = check_result(UV.fs_req_result(req))
188
+ UV.fs_req_cleanup(req)
189
+ UV.free(req)
190
+ @datasync_block.call(e)
191
+ end
192
+
193
+ def on_truncate(req)
194
+ e = check_result(UV.fs_req_result(req))
195
+ UV.fs_req_cleanup(req)
196
+ UV.free(req)
197
+ @truncate_block.call(e)
198
+ end
199
+
200
+ def on_utime(req)
201
+ e = check_result(UV.fs_req_result(req))
202
+ UV.fs_req_cleanup(req)
203
+ UV.free(req)
204
+ @utime_block.call(e)
205
+ end
206
+
207
+ def on_chmod(req)
208
+ e = check_result(UV.fs_req_result(req))
209
+ UV.fs_req_cleanup(req)
210
+ UV.free(req)
211
+ @chmod_block.call(e)
212
+ end
213
+
214
+ def on_chown(req)
215
+ e = check_result(UV.fs_req_result(req))
216
+ UV.fs_req_cleanup(req)
217
+ UV.free(req)
218
+ @chown_block.call(e)
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,35 @@
1
+ module UV
2
+ class File
3
+ class Stat < Struct.new(:atime, :blksize, :blocks, :ctime, :dev, :ftype, :gid, :ino,
4
+ :mode, :mtime, :nlink, :rdev, :size, :uid)
5
+ def blockdev?; end
6
+ def chardev?; end
7
+ def dev_major; end
8
+ def dev_minor; end
9
+ def directory?; end
10
+ def executable?; end
11
+ def executable_real?; end
12
+ def file?; end
13
+ def ftype; end
14
+ def grpowned?; end
15
+ def inspect; end
16
+ def owned?; end
17
+ def pipe?; end
18
+ def rdev_major; end
19
+ def rdev_minor; end
20
+ def readable?; end
21
+ def readable_real?; end
22
+ def setgid?; end
23
+ def setuid?; end
24
+ def size?; end
25
+ def socket?; end
26
+ def sticky?; end
27
+ def symlink?; end
28
+ def world_readable?; end
29
+ def world_writeable?; end
30
+ def writable?; end
31
+ def writable_real?; end
32
+ def zero?; end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,335 @@
1
+ module UV
2
+ class Filesystem
3
+ include Assertions, Resource, Listener
4
+
5
+ def initialize(loop)
6
+ @loop = loop
7
+ end
8
+
9
+ def open(path, flags = 0, mode = 0, &block)
10
+ assert_block(block)
11
+ assert_arity(2, block)
12
+ assert_type(String, path, "path must be a String")
13
+ assert_type(Integer, flags, "flags must be an Integer")
14
+ assert_type(Integer, mode, "mode must be an Integer")
15
+
16
+ @open_block = block
17
+
18
+ check_result! UV.fs_open(loop.to_ptr, UV.create_request(:uv_fs), path, flags, mode, callback(:on_open))
19
+
20
+ self
21
+ end
22
+
23
+ def unlink(path, &block)
24
+ assert_block(block)
25
+ assert_arity(1, block)
26
+ assert_type(String, path, "path must be a String")
27
+
28
+ @unlink_block = block
29
+
30
+ check_result! UV.fs_unlink(loop.to_ptr, UV.create_request(:uv_fs), path, callback(:on_unlink))
31
+
32
+ self
33
+ end
34
+
35
+ def mkdir(path, mode = 0777, &block)
36
+ assert_block(block)
37
+ assert_arity(1, block)
38
+ assert_type(String, path, "path must be a String")
39
+ assert_type(Integer, mode, "mode must be an Integer")
40
+
41
+ @mkdir_block = block
42
+
43
+ check_result! UV.fs_mkdir(loop.to_ptr, UV.create_request(:uv_fs), path, mode, callback(:on_mkdir))
44
+
45
+ self
46
+ end
47
+
48
+ def rmdir(path, &block)
49
+ assert_block(block)
50
+ assert_arity(1, block)
51
+ assert_type(String, path, "path must be a String")
52
+
53
+ @rmdir_block = block
54
+
55
+ check_result! UV.fs_rmdir(loop.to_ptr, UV.create_request(:uv_fs), path, callback(:on_rmdir))
56
+
57
+ self
58
+ end
59
+
60
+ def readdir(path, &block)
61
+ assert_block(block)
62
+ assert_arity(2, block)
63
+ assert_type(String, path, "path must be a String")
64
+
65
+ @readdir_block = block
66
+
67
+ check_result! UV.fs_readdir(loop.to_ptr, UV.create_request(:uv_fs), path, 0, callback(:on_readdir))
68
+
69
+ self
70
+ end
71
+
72
+ def stat(path, &block)
73
+ assert_block(block)
74
+ assert_arity(2, block)
75
+ assert_type(String, path, "path must be a String")
76
+
77
+ @stat_block = block
78
+
79
+ check_result! UV.fs_stat(loop.to_ptr, UV.create_request(:uv_fs), path, callback(:on_stat))
80
+
81
+ self
82
+ end
83
+
84
+ def rename(old_path, new_path, &block)
85
+ assert_block(block)
86
+ assert_arity(1, block)
87
+ assert_type(String, old_path, "old_path must be a String")
88
+ assert_type(String, new_path, "new_path must be a String")
89
+
90
+ @rename_block = block
91
+
92
+ check_result! UV.fs_rename(loop.to_ptr, UV.create_request(:uv_fs), old_path, new_path, callback(:on_rename))
93
+
94
+ self
95
+ end
96
+
97
+ def chmod(path, mode, &block)
98
+ assert_block(block)
99
+ assert_arity(1, block)
100
+ assert_type(String, path, "path must be a String")
101
+ assert_type(Integer, mode, "mode must be an Integer")
102
+
103
+ @chmod_block = block
104
+
105
+ check_result! UV.fs_chmod(loop.to_ptr, UV.create_request(:uv_fs), path, mode, callback(:on_chmod))
106
+
107
+ self
108
+ end
109
+
110
+ def utime(path, atime, mtime, &block)
111
+ assert_block(block)
112
+ assert_arity(1, block)
113
+ assert_type(String, path, "path must be a String")
114
+ assert_type(Integer, atime, "atime must be an Integer")
115
+ assert_type(Integer, mtime, "mtime must be an Integer")
116
+
117
+ @utime_block = block
118
+
119
+ check_result! UV.fs_utime(loop.to_ptr, UV.create_request(:uv_fs), path, atime, mtime, callback(:on_utime))
120
+
121
+ self
122
+ end
123
+
124
+ def lstat(path, &block)
125
+ assert_block(block)
126
+ assert_arity(2, block)
127
+ assert_type(String, path, "path must be a String")
128
+
129
+ @lstat_block = block
130
+
131
+ check_result! UV.fs_lstat(loop.to_ptr, UV.create_request(:uv_fs), path, callback(:on_lstat))
132
+
133
+ self
134
+ end
135
+
136
+ def link(old_path, new_path, &block)
137
+ assert_block(block)
138
+ assert_arity(1, block)
139
+ assert_type(String, old_path, "old_path must be a String")
140
+ assert_type(String, new_path, "new_path must be a String")
141
+
142
+ @link_block = block
143
+
144
+ check_result! UV.fs_link(loop.to_ptr, UV.create_request(:uv_fs), old_path, new_path, callback(:on_link))
145
+
146
+ self
147
+ end
148
+
149
+ def symlink(old_path, new_path, &block)
150
+ assert_block(block)
151
+ assert_arity(1, block)
152
+ assert_type(String, old_path, "old_path must be a String")
153
+ assert_type(String, new_path, "new_path must be a String")
154
+
155
+ @symlink_block = block
156
+
157
+ check_result! UV.fs_symlink(loop.to_ptr, UV.create_request(:uv_fs), old_path, new_path, 0, callback(:on_symlink))
158
+
159
+ self
160
+ end
161
+
162
+ def readlink(path, &block)
163
+ assert_block(block)
164
+ assert_arity(2, block)
165
+ assert_type(String, path, "path must be a String")
166
+
167
+ @readlink_block = block
168
+
169
+ check_result! UV.fs_readlink(loop.to_ptr, UV.create_request(:uv_fs), path, callback(:on_readlink))
170
+
171
+ self
172
+ end
173
+
174
+ def chown(path, uid, gid, &block)
175
+ assert_block(block)
176
+ assert_arity(1, block)
177
+ assert_type(String, path, "path must be a String")
178
+ assert_type(Integer, uid, "uid must be an Integer")
179
+ assert_type(Integer, gid, "gid must be an Integer")
180
+
181
+ @chown_block = block
182
+
183
+ check_result! UV.fs_chown(loop.to_ptr, UV.create_request(:uv_fs), path, uid, gid, callback(:on_chown))
184
+
185
+ self
186
+ end
187
+
188
+ private
189
+ def on_open(req)
190
+ fd = UV.fs_req_result(req)
191
+ e = check_result(fd)
192
+ file = File.new(loop, fd) unless e
193
+
194
+ UV.fs_req_cleanup(req)
195
+ UV.free(req)
196
+
197
+ @open_block.call(e, file)
198
+ end
199
+
200
+ def on_unlink(req)
201
+ e = check_result(UV.fs_req_result(req))
202
+
203
+ UV.fs_req_cleanup(req)
204
+ UV.free(req)
205
+
206
+ @unlink_block.call(e)
207
+ end
208
+
209
+ def on_mkdir(req)
210
+ e = check_result(UV.fs_req_result(req))
211
+
212
+ UV.fs_req_cleanup(req)
213
+ UV.free(req)
214
+
215
+ @mkdir_block.call(e)
216
+ end
217
+
218
+ def on_rmdir(req)
219
+ e = check_result(UV.fs_req_result(req))
220
+
221
+ UV.fs_req_cleanup(req)
222
+ UV.free(req)
223
+
224
+ @rmdir_block.call(e)
225
+ end
226
+
227
+ def on_readdir(req)
228
+ e = check_result(UV.fs_req_result(req))
229
+
230
+ unless e
231
+ string_ptr = UV.fs_req_pointer(req)
232
+ files = string_ptr.null? ? [] : string_ptr.read_string().split("\0")
233
+ end
234
+
235
+ UV.fs_req_cleanup(req)
236
+ UV.free(req)
237
+
238
+ @readdir_block.call(e, files)
239
+ end
240
+
241
+ def on_stat(req)
242
+ e = check_result(UV.fs_req_result(req))
243
+
244
+ unless e
245
+ stat = UV.fs_req_stat(req)
246
+ end
247
+
248
+ UV.fs_req_cleanup(req)
249
+ UV.free(req)
250
+
251
+ @stat_block.call(e, stat)
252
+ end
253
+
254
+ def on_rename(req)
255
+ e = check_result(UV.fs_req_result(req))
256
+
257
+ UV.fs_req_cleanup(req)
258
+ UV.free(req)
259
+
260
+ @rename_block.call(e)
261
+ end
262
+
263
+ def on_chmod(req)
264
+ e = check_result(UV.fs_req_result(req))
265
+
266
+ UV.fs_req_cleanup(req)
267
+ UV.free(req)
268
+
269
+ @chmod_block.call(e)
270
+ end
271
+
272
+ def on_utime(req)
273
+ e = check_result(UV.fs_req_result(req))
274
+
275
+ UV.fs_req_cleanup(req)
276
+ UV.free(req)
277
+
278
+ @utime_block.call(e)
279
+ end
280
+
281
+ def on_lstat(req)
282
+ e = check_result(UV.fs_req_result(req))
283
+
284
+ unless e
285
+ stat = UV.fs_req_stat(req)
286
+ end
287
+
288
+ UV.fs_req_cleanup(req)
289
+ UV.free(req)
290
+
291
+ @lstat_block.call(e, stat)
292
+ end
293
+
294
+ def on_link(req)
295
+ e = check_result(UV.fs_req_result(req))
296
+
297
+ UV.fs_req_cleanup(req)
298
+ UV.free(req)
299
+
300
+ @link_block.call(e)
301
+ end
302
+
303
+ def on_symlink(req)
304
+ e = check_result(UV.fs_req_result(req))
305
+
306
+ UV.fs_req_cleanup(req)
307
+ UV.free(req)
308
+
309
+ @symlink_block.call(e)
310
+ end
311
+
312
+ def on_readlink(req)
313
+ e = check_result(UV.fs_req_result(req))
314
+
315
+ unless e
316
+ string_ptr = UV.fs_req_pointer(req)
317
+ path = string_ptr.read_string() unless string_ptr.null?
318
+ end
319
+
320
+ UV.fs_req_cleanup(req)
321
+ UV.free(req)
322
+
323
+ @readlink_block.call(e, path)
324
+ end
325
+
326
+ def on_chown(req)
327
+ e = check_result(UV.fs_req_result(req))
328
+
329
+ UV.fs_req_cleanup(req)
330
+ UV.free(req)
331
+
332
+ @chown_block.call(e)
333
+ end
334
+ end
335
+ end