Fix for #3229 #4152

merged 27 commits into from Sep 22, 2016


None yet

5 participants

etehtsea commented Sep 13, 2016 edited

Almost full Addrinfo support and many other sockets-related improvements.

fixes #3229

headius and others added some commits Dec 31, 2015
@headius @etehtsea headius First pass at compatibility work on socket subsystem.
This is based on specs created by @yorickpeterse for the
rubysl/rubysl-socket move to a pure-ruby socket lib.

Among the changes thusfar:

* Many improvements to Addrinfo, including leveraging the JDK APIs
  better and having less state. More address types work correctly
* Socket now handles more types of sockets, including servers.
* Improvements to addressing behavior across all socket types.
* In-progress refactoring of socket classes to be reusable from
  Socket grab-bag.

At the moment there are around 565 specs tagged.
@etehtsea etehtsea Fix Addrinfo#inspect_sockaddr
Also tested using specs from ruby/spec#287
@etehtsea etehtsea Fix TCPServer#initialize 6a79100
@etehtsea etehtsea Untag Addrinfo#ip_address spec ac1e4f9
@etehtsea etehtsea Fix Addrinfo#ip_address 51fe6f3
@etehtsea etehtsea Partially fix Addrinfo#inspect
Fix regression exposed by jruby/test_addrinfo test
@etehtsea etehtsea Revert lazy socket initialization changes.
Will be made in the separate PR
@etehtsea etehtsea Add Socket.unpack_sockaddr_un fn
Remove (un)pack_sockaddr_un specs from excludes
@etehtsea etehtsea Put all (un)pack_sockaddr fns to Sockaddr 56b5301
@etehtsea etehtsea Get rid of useless UnixSocketAddress creation 4e62621
@etehtsea etehtsea Finally fix Socket.(un)pack_sockaddr_un
Covered by ruby/spec#290
@etehtsea etehtsea Handle Addrinfo in Socket#unpack_sockaddr_(un|in)
Covered by ruby/spec#290
@etehtsea etehtsea Fix RubyBasicSocket#getsockname
Bring back fallback for unbinded socket
@etehtsea etehtsea Fix TCPSocket#recv_nonblock bce9285
@headius @etehtsea headius Implement ipv4_private? and ipv6_unspecified?. 0949edb
@etehtsea etehtsea Fix Addrinfo#ipv(4|6)_multicast? 4862d2d
@headius @etehtsea headius Add missing AI constants. 120b70c
@headius @etehtsea headius Set up protocol better. da40a15
@headius @etehtsea headius Handle reverse lookup flag properly for IPSocket.addr and peeraddr 3219afe
@headius @etehtsea headius Eliminate "19" versions of these. 53a70b0
@headius @etehtsea headius Improvements for Addrinfo.getaddrinfo. 8990eb6
@headius @etehtsea headius Implement Addrinfo#nameinfo. 590cac8
@etehtsea etehtsea Fix Socket.getaddrinfo regression 06178b2
@etehtsea etehtsea Remove tags from passing rubyspecs 85681bd
@headius @etehtsea headius Accept numeric strings for port. e50459e
@etehtsea etehtsea Fix Addrinfo.(tcp|udp) init with service name
@kares kares and 1 other commented on an outdated diff Sep 13, 2016
@@ -46,51 +48,37 @@
* @author <a href="">Ola Bini</a>
@JRubyClass(name="IPSocket", parent="BasicSocket")
-public class RubyIPSocket extends RubyBasicSocket {
+public abstract class RubyIPSocket extends RubyBasicSocket {
kares Sep 13, 2016 Member

IPSocket is still allocate-able ... not that it matters much (probably doesn't at all)

2.3.1 :029 >
NoMethodError: undefined method `initialize' for #<IPSocket:0x0000000128ed70>
    from (irb):29:in `new'
    from (irb):29
    from /opt/local/rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
2.3.1 :030 > IPSocket.allocate
 => #<IPSocket:0x000000012574b0> 
headius Sep 13, 2016 Member

I presume this means you could extend IPSocket and make your own...not that I know how you'd do that with so much hidden in C.

I agree we should probably undo this change.

headius commented Sep 13, 2016

This is a big PR! Well done stitching your commits and my commits together!

I must raise the issue of whitespace again, though. You have a number of places here changing nothing but whitespace. In such a big PR I don't expect you to go back and fix that, but please be mindful of it in the future and try to set your IDE to not make spurious formatting changes.

I'll review.

headius commented Sep 13, 2016

@etehtsea It looks good to me. Hard to tell which code is yours and which is mine now :-)

The IPSocket abstract/NotAllocatable change should be reverted, but that's all I saw.

Maybe @enebo can weigh in from Japan if he's got a moment.

@headius headius added this to the JRuby milestone Sep 13, 2016
enebo commented Sep 14, 2016

EPIC...I did not spend much time on this but landing sooner and getting it pushed through the meat grinder (e.g. we need some bake + expanded testing).

One other tiny note: context.getRuntime() is fine but it is ok to do context.runtime if you want. We do this in so many places now I think it is an acceptable pattern to access the field.

etehtsea commented Sep 14, 2016 edited

@kares, @headius done. Also reverted for BasicSocket:

JRuby after fix:

>> BasicSocket.allocate
=> #<BasicSocket:0x1f7030a6>
NoMethodError: undefined method `initialize' for #<BasicSocket:0x396f6598>
>> IPSocket.allocate
=> #<IPSocket:0x394e1a0f>
NoMethodError: undefined method `initialize' for #<IPSocket:0x1d29cf23>

MRI 2.3.1:

[1] pry(main)> BasicSocket.allocate
=> #<BasicSocket:0x007fb4eb5292a0>
[2] pry(main)>
NoMethodError: undefined method `initialize' for #<BasicSocket:0x007fb4eb4f0950>
from (pry):2:in `new'
[3] pry(main)> IPSocket.allocate
=> #<IPSocket:0x007fb4eb4bb408>
[4] pry(main)>
NoMethodError: undefined method `initialize' for #<IPSocket:0x007fb4e9c5f918>

Related to space trimming and context.runtime: I'll take this into account.

@etehtsea etehtsea Revert abstract/NotAllocatable changes
Make RubyBasicSocket and RubyIPSocket allocatable to match MRI behaviour
@headius headius merged commit cc619c0 into jruby:master Sep 22, 2016

1 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
continuous-integration/travis-ci/pr The Travis CI build passed
@etehtsea etehtsea deleted the etehtsea:socket-next-re branch Sep 22, 2016
headius commented Sep 22, 2016

@eregon I think we need to address the rubysl-socket spec question. The specs there are considerably more complete, and appear to be licensed BSD. I think we should pull them into ruby/spec, so we can all start running them as part of that suite.

eregon commented Nov 27, 2016

@headius I missed this message, but essentially I think the simplest for now is to integrate the rubysl-socket specs in CI separately, as there is an overlap between both kind of specs and I'm unsure what to do LICENSE-wise.

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