uringmachine 0.3 → 0.5
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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -1
- data/CHANGELOG.md +23 -0
- data/README.md +128 -0
- data/TODO.md +14 -0
- data/examples/bm_snooze.rb +89 -0
- data/examples/bm_write.rb +56 -0
- data/examples/dns_client.rb +12 -0
- data/examples/echo_server.rb +18 -40
- data/examples/http_server.rb +42 -43
- data/examples/inout.rb +19 -0
- data/examples/nc.rb +36 -0
- data/examples/server_client.rb +64 -0
- data/examples/snooze.rb +44 -0
- data/examples/write_dev_null.rb +16 -0
- data/ext/um/extconf.rb +24 -23
- data/ext/um/um.c +524 -278
- data/ext/um/um.h +146 -44
- data/ext/um/um_buffer.c +49 -0
- data/ext/um/um_class.c +217 -106
- data/ext/um/um_const.c +213 -0
- data/ext/um/um_ext.c +4 -0
- data/ext/um/um_mutex_class.c +47 -0
- data/ext/um/um_op.c +86 -114
- data/ext/um/um_queue_class.c +58 -0
- data/ext/um/um_sync.c +273 -0
- data/ext/um/um_utils.c +49 -4
- data/lib/uringmachine/dns_resolver.rb +84 -0
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +28 -0
- data/supressions/ruby.supp +71 -0
- data/test/helper.rb +8 -0
- data/test/test_um.rb +685 -46
- data/vendor/liburing/.github/workflows/build.yml +29 -1
- data/vendor/liburing/.gitignore +6 -0
- data/vendor/liburing/CHANGELOG +16 -0
- data/vendor/liburing/CONTRIBUTING.md +165 -0
- data/vendor/liburing/configure +64 -0
- data/vendor/liburing/examples/Makefile +9 -1
- data/vendor/liburing/examples/kdigest.c +405 -0
- data/vendor/liburing/examples/proxy.c +75 -8
- data/vendor/liburing/examples/reg-wait.c +159 -0
- data/vendor/liburing/liburing.pc.in +1 -1
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/Makefile +16 -2
- data/vendor/liburing/src/include/liburing/io_uring.h +77 -0
- data/vendor/liburing/src/include/liburing/sanitize.h +39 -0
- data/vendor/liburing/src/include/liburing.h +59 -6
- data/vendor/liburing/src/int_flags.h +10 -3
- data/vendor/liburing/src/liburing-ffi.map +16 -0
- data/vendor/liburing/src/liburing.map +10 -0
- data/vendor/liburing/src/queue.c +28 -16
- data/vendor/liburing/src/register.c +106 -1
- data/vendor/liburing/src/sanitize.c +176 -0
- data/vendor/liburing/src/setup.c +47 -19
- data/vendor/liburing/src/setup.h +6 -0
- data/vendor/liburing/test/35fa71a030ca.c +7 -0
- data/vendor/liburing/test/500f9fbadef8.c +2 -0
- data/vendor/liburing/test/7ad0e4b2f83c.c +0 -25
- data/vendor/liburing/test/917257daa0fe.c +7 -0
- data/vendor/liburing/test/Makefile +38 -4
- data/vendor/liburing/test/a0908ae19763.c +7 -0
- data/vendor/liburing/test/a4c0b3decb33.c +7 -0
- data/vendor/liburing/test/accept.c +14 -4
- data/vendor/liburing/test/b19062a56726.c +7 -0
- data/vendor/liburing/test/bind-listen.c +2 -2
- data/vendor/liburing/test/buf-ring-nommap.c +10 -3
- data/vendor/liburing/test/buf-ring.c +2 -0
- data/vendor/liburing/test/cmd-discard.c +427 -0
- data/vendor/liburing/test/coredump.c +7 -0
- data/vendor/liburing/test/cq-overflow.c +13 -1
- data/vendor/liburing/test/d4ae271dfaae.c +11 -3
- data/vendor/liburing/test/defer-taskrun.c +2 -2
- data/vendor/liburing/test/defer-tw-timeout.c +4 -1
- data/vendor/liburing/test/defer.c +2 -2
- data/vendor/liburing/test/double-poll-crash.c +1 -1
- data/vendor/liburing/test/eeed8b54e0df.c +2 -0
- data/vendor/liburing/test/eventfd.c +0 -1
- data/vendor/liburing/test/exit-no-cleanup.c +11 -0
- data/vendor/liburing/test/fadvise.c +9 -26
- data/vendor/liburing/test/fdinfo.c +9 -1
- data/vendor/liburing/test/fifo-nonblock-read.c +69 -0
- data/vendor/liburing/test/file-exit-unreg.c +48 -0
- data/vendor/liburing/test/file-register.c +14 -2
- data/vendor/liburing/test/file-update.c +1 -1
- data/vendor/liburing/test/file-verify.c +27 -16
- data/vendor/liburing/test/files-exit-hang-timeout.c +1 -2
- data/vendor/liburing/test/fixed-buf-iter.c +3 -1
- data/vendor/liburing/test/fixed-hugepage.c +12 -1
- data/vendor/liburing/test/fsnotify.c +1 -0
- data/vendor/liburing/test/futex.c +16 -4
- data/vendor/liburing/test/helpers.c +47 -0
- data/vendor/liburing/test/helpers.h +6 -0
- data/vendor/liburing/test/init-mem.c +5 -3
- data/vendor/liburing/test/io-cancel.c +0 -24
- data/vendor/liburing/test/io_uring_passthrough.c +4 -0
- data/vendor/liburing/test/io_uring_register.c +38 -8
- data/vendor/liburing/test/iopoll-leak.c +4 -0
- data/vendor/liburing/test/iopoll-overflow.c +1 -1
- data/vendor/liburing/test/iopoll.c +3 -3
- data/vendor/liburing/test/kallsyms.c +203 -0
- data/vendor/liburing/test/link-timeout.c +159 -0
- data/vendor/liburing/test/linked-defer-close.c +224 -0
- data/vendor/liburing/test/madvise.c +12 -25
- data/vendor/liburing/test/min-timeout-wait.c +0 -25
- data/vendor/liburing/test/min-timeout.c +0 -25
- data/vendor/liburing/test/mkdir.c +6 -0
- data/vendor/liburing/test/msg-ring.c +8 -2
- data/vendor/liburing/test/napi-test.c +16 -3
- data/vendor/liburing/test/no-mmap-inval.c +3 -1
- data/vendor/liburing/test/nop.c +44 -0
- data/vendor/liburing/test/ooo-file-unreg.c +1 -1
- data/vendor/liburing/test/open-close.c +40 -0
- data/vendor/liburing/test/openat2.c +37 -14
- data/vendor/liburing/test/poll-many.c +13 -7
- data/vendor/liburing/test/poll-mshot-update.c +17 -10
- data/vendor/liburing/test/poll-v-poll.c +6 -3
- data/vendor/liburing/test/pollfree.c +148 -0
- data/vendor/liburing/test/read-mshot-empty.c +158 -153
- data/vendor/liburing/test/read-mshot-stdin.c +121 -0
- data/vendor/liburing/test/read-mshot.c +282 -27
- data/vendor/liburing/test/read-write.c +78 -13
- data/vendor/liburing/test/recv-msgall-stream.c +3 -0
- data/vendor/liburing/test/recv-msgall.c +5 -0
- data/vendor/liburing/test/recvsend_bundle-inc.c +680 -0
- data/vendor/liburing/test/recvsend_bundle.c +94 -31
- data/vendor/liburing/test/reg-fd-only.c +15 -5
- data/vendor/liburing/test/reg-wait.c +251 -0
- data/vendor/liburing/test/regbuf-clone.c +645 -0
- data/vendor/liburing/test/regbuf-merge.c +7 -0
- data/vendor/liburing/test/register-restrictions.c +86 -85
- data/vendor/liburing/test/rename.c +59 -1
- data/vendor/liburing/test/resize-rings.c +643 -0
- data/vendor/liburing/test/ringbuf-read.c +5 -0
- data/vendor/liburing/test/ringbuf-status.c +5 -1
- data/vendor/liburing/test/rsrc_tags.c +1 -1
- data/vendor/liburing/test/runtests.sh +16 -1
- data/vendor/liburing/test/send-zerocopy.c +59 -0
- data/vendor/liburing/test/short-read.c +1 -0
- data/vendor/liburing/test/socket.c +43 -0
- data/vendor/liburing/test/splice.c +3 -1
- data/vendor/liburing/test/sq-poll-dup.c +1 -1
- data/vendor/liburing/test/sq-poll-share.c +2 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +8 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +1 -25
- data/vendor/liburing/test/sqpoll-sleep.c +40 -33
- data/vendor/liburing/test/sqwait.c +136 -0
- data/vendor/liburing/test/statx.c +89 -0
- data/vendor/liburing/test/stdout.c +2 -0
- data/vendor/liburing/test/submit-and-wait.c +1 -25
- data/vendor/liburing/test/submit-reuse.c +4 -26
- data/vendor/liburing/test/symlink.c +12 -1
- data/vendor/liburing/test/sync-cancel.c +56 -22
- data/vendor/liburing/test/thread-exit.c +5 -0
- data/vendor/liburing/test/timeout-new.c +1 -26
- data/vendor/liburing/test/timeout.c +25 -34
- data/vendor/liburing/test/unlink.c +94 -1
- data/vendor/liburing/test/uring_cmd_ublk.c +1252 -0
- data/vendor/liburing/test/waitid.c +62 -8
- data/vendor/liburing/test/wq-aff.c +35 -0
- data/vendor/liburing/test/xfail_prep_link_timeout_out_of_scope.c +46 -0
- data/vendor/liburing/test/xfail_register_buffers_out_of_scope.c +51 -0
- metadata +37 -6
- data/examples/event_loop.rb +0 -69
- data/examples/fibers.rb +0 -105
- data/examples/http_server_multishot.rb +0 -57
- data/examples/http_server_simpler.rb +0 -34
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'resolv'
|
4
|
+
|
5
|
+
class UringMachine
|
6
|
+
class DNSResolver
|
7
|
+
def initialize(machine)
|
8
|
+
@machine = machine
|
9
|
+
@requests = UM::Queue.new
|
10
|
+
@nameservers = get_nameservers
|
11
|
+
@fiber = @machine.spin { handle_requests_loop }
|
12
|
+
@last_id = 0
|
13
|
+
@cache = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def resolve(hostname, type)
|
17
|
+
@machine.push(@requests, [hostname, type, Fiber.current])
|
18
|
+
@machine.yield
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_requests_loop
|
22
|
+
while true
|
23
|
+
hostname, type, fiber = @machine.shift(@requests)
|
24
|
+
res = do_resolve(hostname, type)
|
25
|
+
@machine.schedule(fiber, res)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_nameservers
|
30
|
+
nameservers = []
|
31
|
+
IO.readlines('/etc/resolv.conf').each do |line|
|
32
|
+
if line =~ /^nameserver (.+)$/
|
33
|
+
nameservers << $1.split(/\s+/).first
|
34
|
+
end
|
35
|
+
end
|
36
|
+
nameservers
|
37
|
+
end
|
38
|
+
|
39
|
+
def socket_fd
|
40
|
+
@socket_fd ||= prepare_socket
|
41
|
+
end
|
42
|
+
|
43
|
+
def prepare_socket
|
44
|
+
fd = @machine.socket(UM::AF_INET, UM::SOCK_DGRAM, 0, 0)
|
45
|
+
@machine.bind(fd, '0.0.0.0', 0)
|
46
|
+
@machine.connect(fd, @nameservers.sample, 53)
|
47
|
+
fd
|
48
|
+
end
|
49
|
+
|
50
|
+
def do_resolve(hostname, type, try_count = 0)
|
51
|
+
fd = socket_fd
|
52
|
+
req = prepare_request_packet(hostname, type)
|
53
|
+
msg = req.encode
|
54
|
+
@machine.send(fd, msg, msg.bytesize, 0)
|
55
|
+
|
56
|
+
buf = +''
|
57
|
+
@machine.recv(fd, buf, 16384, 0)
|
58
|
+
|
59
|
+
msg = Resolv::DNS::Message.decode buf
|
60
|
+
addrs = []
|
61
|
+
msg.each_answer do |name, ttl, data|
|
62
|
+
p [name, ttl, data]
|
63
|
+
if data.kind_of?(Resolv::DNS::Resource::IN::A) ||
|
64
|
+
data.kind_of?(Resolv::DNS::Resource::IN::AAAA)
|
65
|
+
addrs << data.address.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
addrs
|
69
|
+
end
|
70
|
+
|
71
|
+
def prepare_request_packet(hostname, type)
|
72
|
+
msg = Resolv::DNS::Message.new
|
73
|
+
msg.id = (@last_id += 1)
|
74
|
+
msg.rd = 1
|
75
|
+
msg.add_question hostname, msg_type(type)
|
76
|
+
msg
|
77
|
+
end
|
78
|
+
|
79
|
+
def msg_type(type)
|
80
|
+
# TODO: add support for other types
|
81
|
+
Resolv::DNS::Resource::IN::A
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/uringmachine/version.rb
CHANGED
data/lib/uringmachine.rb
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative './um_ext'
|
4
|
+
require_relative 'uringmachine/dns_resolver'
|
4
5
|
|
5
6
|
UM = UringMachine
|
7
|
+
|
8
|
+
class UringMachine
|
9
|
+
@@fiber_map = {}
|
10
|
+
|
11
|
+
def spin(value = nil, &block)
|
12
|
+
f = Fiber.new do |resume_value|
|
13
|
+
block.(resume_value)
|
14
|
+
rescue Exception => e
|
15
|
+
STDERR.puts "Unhandled fiber exception: #{e.inspect}"
|
16
|
+
STDERR.puts e.backtrace.join("\n")
|
17
|
+
exit
|
18
|
+
ensure
|
19
|
+
@@fiber_map.delete(f)
|
20
|
+
# yield control
|
21
|
+
self.yield
|
22
|
+
p :bad_bad_bad
|
23
|
+
end
|
24
|
+
schedule(f, value)
|
25
|
+
@@fiber_map[f] = true
|
26
|
+
f
|
27
|
+
end
|
28
|
+
|
29
|
+
def resolve(hostname, type = :A)
|
30
|
+
@resolver ||= DNSResolver.new(self)
|
31
|
+
@resolver.resolve(hostname, type)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
{
|
2
|
+
On platforms where memcpy is safe for overlapped memory, the compiler will sometimes replace memmove with memcpy. Valgrind may report a false positive.
|
3
|
+
Memcheck:Overlap
|
4
|
+
fun:__memcpy_chk
|
5
|
+
fun:memmove
|
6
|
+
...
|
7
|
+
}
|
8
|
+
{
|
9
|
+
Requiring a file will add it to the loaded features, which may be reported as a leak.
|
10
|
+
Memcheck:Leak
|
11
|
+
...
|
12
|
+
fun:require_internal
|
13
|
+
...
|
14
|
+
}
|
15
|
+
{
|
16
|
+
recursive_list_access creates a hash called `list` that is stored on the threadptr_recursive_hash. This is reported as a memory leak.
|
17
|
+
Memcheck:Leak
|
18
|
+
...
|
19
|
+
fun:rb_ident_hash_new
|
20
|
+
fun:recursive_list_access
|
21
|
+
fun:exec_recursive
|
22
|
+
...
|
23
|
+
}
|
24
|
+
{
|
25
|
+
"Invalid read of size 8" when marking the stack of fibers
|
26
|
+
Memcheck:Addr8
|
27
|
+
fun:each_location*
|
28
|
+
...
|
29
|
+
}
|
30
|
+
{
|
31
|
+
Rust probes for statx(buf), will be fixed in Valgrind >= 3.1.6.0
|
32
|
+
Memcheck:Param
|
33
|
+
statx(buf)
|
34
|
+
...
|
35
|
+
fun:*try_statx*
|
36
|
+
...
|
37
|
+
}
|
38
|
+
{
|
39
|
+
Rust probes for statx(file_name), will be fixed in Valgrind >= 3.1.6.0
|
40
|
+
Memcheck:Param
|
41
|
+
statx(file_name)
|
42
|
+
...
|
43
|
+
fun:*try_statx*
|
44
|
+
...
|
45
|
+
}
|
46
|
+
{
|
47
|
+
strscan_do_scan in strscan.c will sometimes replace the ptr of the regex, which can be reported as a memory leak if the regex is stored in an iseq. https://github.com/ruby/ruby/pull/8136
|
48
|
+
Memcheck:Leak
|
49
|
+
...
|
50
|
+
fun:rb_reg_prepare_re
|
51
|
+
fun:strscan_do_scan
|
52
|
+
...
|
53
|
+
}
|
54
|
+
{
|
55
|
+
The callcache table (RCLASS_CC_TBL) is lazily created, so it is allocated when the first method that gets cached. If this happens in a native extension, it may be reported as a memory leak.
|
56
|
+
Memcheck:Leak
|
57
|
+
...
|
58
|
+
fun:rb_id_table_create
|
59
|
+
...
|
60
|
+
fun:rb_callable_method_entry
|
61
|
+
...
|
62
|
+
}
|
63
|
+
{
|
64
|
+
The date library lazily initializes Regexps using static local variables through the function `regcomp`. The Regexp will end up being reported as a memory leak.
|
65
|
+
Memcheck:Leak
|
66
|
+
...
|
67
|
+
fun:rb_enc_reg_new
|
68
|
+
...
|
69
|
+
fun:date__parse
|
70
|
+
...
|
71
|
+
}
|
data/test/helper.rb
CHANGED