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
IO::Socket::INET Documentation Inconsistency [PF_INET as a default] #2162
Comments
It doesn't. It returns a Does this give any errors?
Are you sure that's the only line for connecting? I do see an
In the code I see |
Here is a full session:
You'll notice it only attempts ipv6. The command you asked me to run provides:
If I expand that, with using truss to capture what it's doing as far as connecting is concerned:
Edit: and yes, my mistake with :family(string) .... still learning. The problem however still exists without that small blunder of mine. |
OK, so looks like even with @Kaiepi would you have an idea about what's going on? I think you might be familiar with this area... and have FreeBSD on hand. |
Some notes which I think is related: In:
As the notes say, family is derived from the port: (port >>16) & USHORT_MAX Assuming it is 0, this is essentially whateveryougot '*' in perl6.. The routine MVM_io_resolve_host_name seems to be broken for several reasons.
Anyways, I'm not 100% sure of any of this, but useful notes here for whoever is more familiar with MoarVM which I am not. EDIT: []https://github.com/rakudo/rakudo/blob/master/src/core/IO/Socket/INET.pm6 line 117 reads:
These hardcoded values seem strange too. Are these values families? It seems like it. 10 is PF_INET6 on Linux This has got to be part of the problem I would think. Seems coincidental if it isn't. |
Attached you'll find an untested patch that addresses one of the three issues I pointed out. It changes the behavior of MVM_io_resolve_host_name to return the addrinfo * from the routine instead of sockaddr. The returned addrinfo is then looped upon within the socket_connect routine trying all returned hosts until one is successful or they all fail. What this still doesn't address is . . . . Why PF_INET6 when I'm explicitly setting PF_INET. I shouldn't have to set it at all in fact, it's the default. line 117 of IO::Socket::INET.pm6:
^^ possibly related hardcoded values for socket families by the looks of it |
FWIW, I use Z-Script and its |
Thanks for that. My problem is fixed with patches I wrote: Problem 1 - rakudo/src/core/IO/Socket/INET.pm6
The parameter here does nothing. A parameter is required, but it isn't used in the C function body. Problem 2 - :family does nothing for outbound sockets.As pointed out already and described within the C source code, the port parameter that gets passed around is expecting the family to be available within the port variable at bits 16-63. I've supplied a patch that essentially provides this as it expects but it feels so so so wrong:
This needs to be evaluated. Problem 3 - Connection attempts are only done on one host returned by getaddrinfo.If there are 1 or more hosts and 1 is having a problem temporarily, it's a disservice not to attempt the other hosts. Attached patch has logic, but it's not tested. Problem 4 - My MoarVM experience is shit.My patches work for me(tm) and have only been tested on FreeBSD using syncsocket's. asyncsockets NEED to be reviewed as well. Patches -MoarVM.syncsocketh.diff.txt Example -% truss -o data perl6 -e 'given IO::Socket::INET.new(:host<www.google.com>, :port<443>) { .print: "trash\r\n";.recv.say }' % egrep 'connect|socket' data Notes -
This is because it just so happens that PF_INET has the correct numerical value defined in IO::Socket::INET. |
Can confirm this happens on my FreeBSD machine:
If having the system's values for
This would break async sockets as is since they don't pass the family down through
|
The documentation on IO::Socket::INET shows PF_INET being a default for the family argument to new.
However, it is defaulting to PF_INET6:
perl6 -e 'my \a = IO::Socket::INET.new(:host<www.google.com>, :port<443>);'
Could not connect socket: No route to host
in block at -e line 1
Here's a truss (FreeBSD) showing this:
socket(PF_INET6,SOCK_STREAM,0) = 17 (0x11)
connect(17,{ AF_INET6 [2607:f8b0:4002:c0c::67]:443 },28) ERR#65 'No route to host'
It never attempts ipv4.
The following works as expected:
perl6 -e 'my \a = IO::Socket::INET.new(:host<www.google.com>, :port<443>, :family<PF_INET>);'
I suspect this is an actual bug rather than a documentation problem as it makes more sense that PF_INET be the default.
Environment
The text was updated successfully, but these errors were encountered: