Skip to content

Commit 1c66124

Browse files
committed
Make Addrinfo objects Ractor shareable
Allow Addrinfo objects to be shared among Ractors. Addrinfo objects are already immutable, so I think it's safe for us to tag them as RUBY_TYPED_FROZEN_SHAREABLE shareable too.
1 parent b08e20d commit 1c66124

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/socket/raddrinfo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ addrinfo_memsize(const void *ptr)
12111211
static const rb_data_type_t addrinfo_type = {
12121212
"socket/addrinfo",
12131213
{addrinfo_mark, addrinfo_free, addrinfo_memsize,},
1214+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE,
12141215
};
12151216

12161217
static VALUE

test/socket/test_addrinfo.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ def test_family_addrinfo
360360
assert_raise(Socket::ResolutionError) { Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("::1", 80) }
361361
end
362362

363+
def test_ractor_shareable
364+
assert_ractor(<<~'RUBY', require: 'socket', timeout: 60)
365+
Ractor.make_shareable Addrinfo.new "\x10\x02\x14\xE9\xE0\x00\x00\xFB\x00\x00\x00\x00\x00\x00\x00\x00".b
366+
RUBY
367+
end
368+
363369
def random_port
364370
# IANA suggests dynamic port for 49152 to 65535
365371
# http://www.iana.org/assignments/port-numbers

0 commit comments

Comments
 (0)