getsockname and getpeername should return a struct sockaddr
-----------------------------------------------------------
Key: JRUBY-3563
URL: http://jira.codehaus.org/browse/JRUBY-3563
Project: JRuby
Issue Type: Bug
Components: RubySpec
Affects Versions: JRuby 1.2
Environment: Mac OS X 10.5 Intel and Solaris 10 x86
Reporter: Clayton Wheeler
Attachments: getpeername_spec.patch, getsockname.patch
JRuby's Socket#getsockname returns the result of
java.net.InetSocketAddress#toString() instead of a packed struct sockaddr,
which is the MRI behavior as well as what is expected by RubySpec. This causes
a number of RubySpec failures in the socket tests, some of which mask other
bugs. For instance, spec/ruby/library/socket/udpsocket/bind_spec.rb has a
"binds to INADDR_ANY if the hostname is empty" test that is failing from the
getsockname issue, but the actual bind / INADDR_ANY behavior is wrong as well.
This presumably is also wrong for getpeername, which should be fixed at the
same time. The RubySpec tests for getpeername
(spec/ruby/library/socket/basicsocket/getpeername_spec.rb) have the current
(broken) JRuby behavior special-cased in.
See also JRUBY-2739; this will partially fix that.
The attached patch, getsockname.patch, adds IP-specific getsockname and
getpeername implementations to RubyIPSocket that call pack_sockaddr_in,
returning the same value as on MRI. It also refactors pack_sockaddr_in in
RubySocket to add a directly-Java-callable form and fixes a bug in its packing
logic by building a byte array directly rather than a char array.
It doesn't handle Unix-domain sockets or RubySocket instances, so one test
still fails in getsockname_spec.rb.
This will break the getpeername RubySpec test, as mentioned above; if this
patch is accepted I'll submit the appropriate patch against RubySpec.
==== Test ====
$ ./spec/mspec/bin/mspec run -t j
spec/ruby/library/socket/basicsocket/getsockname_spec.rb
==== BEFORE ====
$ ./spec/mspec/bin/mspec run -t j
spec/ruby/library/socket/basicsocket/getsockname_spec.rb
jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-04-10 rev 9531) [i386-java]
EEE
1)
Socket::BasicSocket#getsockname returns the sockaddr associacted with the
socket ERROR
ArgumentError: can't resolve socket address of wrong type
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:12
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:4
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:55:in
`load'
2)
Socket::BasicSocket#getsockname works on sockets listening in ipaddr_any ERROR
ArgumentError: can't resolve socket address of wrong type
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:18
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:4
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:55:in
`load'
3)
Socket::BasicSocket#getsockname returns empty sockaddr for unbinded sockets
ERROR
IOError: Not Supported
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:25
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:4
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:55:in
`load'
Finished in 0.197000 seconds
1 file, 3 examples, 3 expectations, 0 failures, 3 errors
==== AFTER ====
$ ./spec/mspec/bin/mspec run -t j
spec/ruby/library/socket/basicsocket/getsockname_spec.rb
jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-04-11 rev 9531) [i386-java]
..E
1)
Socket::BasicSocket#getsockname returns empty sockaddr for unbinded sockets
ERROR
IOError: Not Supported
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:25
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:4
/Users/csw/src/jruby-1_2/spec/ruby/library/socket/basicsocket/getsockname_spec.rb:55:in
`load'
Finished in 0.201000 seconds
1 file, 3 examples, 6 expectations, 0 failures, 1 error
[with getpeername_spec.patch]
$ ./spec/mspec/bin/mspec run -t j
spec/ruby/library/socket/basicsocket/getpeername_spec.rb
jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-04-11 rev 9531) [i386-java]
..
Finished in 0.184000 seconds
1 file, 2 examples, 2 expectations, 0 failures, 0 errors
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email