Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.sockaddr_in doesn't seem to work with integers. #3361

Closed
tenderlove opened this issue Dec 20, 2023 · 1 comment · Fixed by #3364
Closed

Socket.sockaddr_in doesn't seem to work with integers. #3361

tenderlove opened this issue Dec 20, 2023 · 1 comment · Fixed by #3364

Comments

@tenderlove
Copy link
Contributor

This code works on CRuby but not TruffleRuby:

$ ruby -v -rsocket -e'p Socket.sockaddr_in(0, Socket::INADDR_ANY)'
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
"\x10\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
$ ruby -v -rsocket -e'p Socket.sockaddr_in(0, Socket::INADDR_ANY)'
truffleruby 23.1.1, like ruby 3.2.2, Oracle GraalVM Native [aarch64-darwin]
/Users/aaron/.rubies/arm64/truffleruby-23.1.1/lib/truffle/socket/truffle/foreign.rb:280:in `pack_sockaddr_in': undefined method `empty?' for 0:Integer (NoMethodError)
	from /Users/aaron/.rubies/arm64/truffleruby-23.1.1/lib/truffle/socket/socket.rb:237:in `pack_sockaddr_in'
	from -e:1:in `<main>'

I haven't tried investigating the problem yet, just wanted to file the issue so it doesn't get lost. Thanks!

@mtortonesi
Copy link
Contributor

Could probably be fixed by something like this?

diff --git a/lib/truffle/socket/truffle/foreign.rb b/lib/truffle/socket/truffle/foreign.rb
index 9ea5838d68..d97b890831 100644
--- a/lib/truffle/socket/truffle/foreign.rb
+++ b/lib/truffle/socket/truffle/foreign.rb
@@ -277,7 +277,7 @@ module Truffle
         hints[:ai_socktype] = type
         hints[:ai_flags]    = flags
 
-        if host and host.empty?
+        if host == Socket::INADDR_ANY || (host and host.empty?)
           host = '0.0.0.0'
         end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants