Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
JRuby 126.96.36.199 Socket.tcp, Addrinfo.tcp, etc. mistake port for protocol #3067
JRuby's Addrinfo implementation incorrectly returns the port number as the protocol:
It still is a problem in 188.8.131.52.rc1: https://github.com/jruby/jruby/blob/184.108.40.206.rc1/core/src/main/java/org/jruby/ext/socket/Addrinfo.java#L263-L266
afamily 2 is PF_INET (ipv4), socktype of 1 is SOCK_STREAM, and protocol 6 is TCP (according to /etc/protocols on Mac OS X)
The code as written in JRuby was attempting to use the "protocol" argument (port) as "protocol family". This was a misunderstanding on my part. Protocol here means "service" and is passed as the third argument to socket(2).
Interestingly, simply ignoring this parameter appears to work fine. The socket still must be bound to a remote host and port anyway. I believe the socket(2) parameter is used for purposes that have no equivalent on JDK.
Ok, I've figured it out.
The logic here goes like this:
Since we already have branching logic based on domain and family to choose the right kind of IO channel, I am not sure we need to do anything with the protocol (and I'm not sure we can do anything). There are probably some exotic domain+family combinations that have multiple protocols, but it appears to be a relic.
My change will properly save and report protocol from Addrinfo and within Socket constructors, but will not use that protocol for any purpose. This appears to pass your case and may be as close as we need to get.