Skip to content

Commit 800789f

Browse files
mtortonesiandrykonchin
authored andcommitted
Properly handle argument Socket::INADDR_ANY in Socket.sockaddr_in.
This should fix issue 3361.
1 parent 7c5bef1 commit 800789f

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Compatibility:
2121
* Promote `File#path` and `File#to_path` to `IO#path` and `IO#to_path` and make IO#new accept an optional `path:` keyword argument (#3039, @moste00)
2222
* Display "unhandled exception" as the message for `RuntimeError` instances with an empty message (#3255, @nirvdrum).
2323
* Set `RbConfig::CONFIG['configure_args']` for openssl and libyaml (#3170, #3303, @eregon).
24+
* Support `Socket.sockaddr_in(port, Socket::INADDR_ANY)` (#3361, @mtortonesi).
2425

2526
Performance:
2627

lib/truffle/socket/truffle/foreign.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def self.pack_sockaddr_in(host, port, family = ::Socket::AF_UNSPEC,
277277
hints[:ai_socktype] = type
278278
hints[:ai_flags] = flags
279279

280-
if host and host.empty?
280+
if host == ::Socket::INADDR_ANY or (host and host.empty?)
281281
host = '0.0.0.0'
282282
end
283283

spec/ruby/library/socket/shared/pack_sockaddr.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
sockaddr_in = Socket.public_send(@method, nil, '127.0.0.1')
1919
Socket.unpack_sockaddr_in(sockaddr_in).should == [0, '127.0.0.1']
20+
21+
sockaddr_in = Socket.public_send(@method, 80, Socket::INADDR_ANY)
22+
Socket.unpack_sockaddr_in(sockaddr_in).should == [80, '0.0.0.0']
2023
end
2124

2225
platform_is_not :solaris do

0 commit comments

Comments
 (0)