-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Differences between Socket.sockaddr_in in jruby vs ruby #4863
Comments
You'd do best to not look under the covers of Sockaddr_in and friends on JRuby; we're not using native structures, so they're likely going to differ from what the platform says. The difference in your case may be a real bug, but I find the exposure of Sockaddr_in and friends in the Ruby API to be serious code smells. It's usually difficult to write code using it that works across platform, and it's forcing an arbitrary, hidden implementation detail on users of the library. That said, I know we should at least be consistent. Why are you looking at the Sockaddr_in bytes at all? |
I guess actually what I really wanted was |
@ChuckWoodraska Ok, that makes things a little clearer for me. So the short answer is that you won't be able to use JRuby for this right now without a platform-appropriate sockaddr_in. The long answer is that we're probably going to need to move toward native sockets soon anyway. That will probably be easiest if we can adopt the FFI-based socket library that @yorickpeterse wrote, but it will take some work to get there since it depends on another Ruby VM's internals. Another option, which isn't super attractive but probably less work, is to simply do a better job of outputting proper sockaddr_in for each platform. As far as I can tell, none of our output is right on macos, and it doesn't appear to be right for you either. |
Ping @enebo...there's many reasons for going to native sockets, but I'm not sure of the right path. A jnr-socket library would be very useful for way more than just JRuby, but we'd be doing a lot of the work by hand...unless we can get jnr-clang working. |
@headius yeah navigating the proper path here is likely the path of least support but still 100% correct. I agree that jnr-something would work but it would be quite a bit of ongoing support. ffi does not really reduce that work much but yorick's library would cut out quite a bit of the initial work. The support would be large either way though? Being in Ruby would likely allow more people to PR? I lean slightly to Ruby FFI vs JNR but only because so few people want to support our JNR stuff. Another question is whether we can really use these byte addrs at all right now? I mean we are providing them because MRI does but can how can we use them. I understand the reporter just wants to compare them so if we just did an ffi call for just Sockaddr_in what would break? I mean both ways so you can convert those bytes back to something our Java impl can use. |
@enebo The uses I've seen for these APIs mostly just want to capture some structure representing the The case reported here is somewhere in the middle; @ChuckWoodraska wants to be able to read in a log from The bytes we present are...unusual. I'm not sure what they match now. These structures could very easily have changed from 32 to 64 bit as well. In any case, nobody seems to understand them but us, so we can't read in those log entries. I think for uses of |
This would be fixed by supporting the FFI-based rubysl-socket library, but probably not otherwise. I have opened #6334 for that goal, though I'm not sure when we will get to it. |
Where does |
Answering my own question - now at https://github.com/rubinius/ruby-stdlib/tree/master/lib/socket. |
Environment
Provide at least:
jruby -v
) and command line (flags, JRUBY_OPTS, etc)jruby 9.1.13.0 (2.3.3) 2017-09-06 8e1c115 Java HotSpot(TM) 64-Bit Server VM 25.144-b01 on 1.8.0_144-b01 +indy +jit [linux-x86_64]
uname -a
)Linux 4.4.0-98-generic cext will only compile if warnings are lenient. #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Other relevant info you may wish to add:
Its the logstash 6.0.0 version of jruby
Expected Behavior
I expect:
Socket.sockaddr_in(80, "127.0.0.1")
to output: "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
Actual Behavior
this version of jruby it outputs: "\x00\x02\x00P\xD0+f\xFA\x00\x00\x00\x00\x00\x00\x00\x00"
which looks like it the first two bytes are switched
The text was updated successfully, but these errors were encountered: