<FromGitter>
<636f7374> Hi everyone, I would like to ask a question about (C `socklen_t *restrict`). ⏎ Why doesn't `Pointer(LibC::SocklenT).new(sizeof(LibC::IfName).to_u32)` work? (return `-1`), but protected `Socket.system_getsockopt` works fine (return `0`). ⏎ What am I doing wrong? I'm a `rookie` in C language. :(.
<FromGitter>
<636f7374> I feel that this is related to C `*restrict`, but it seems that `Crystal Docs` doesn't say how to deal with `*restrict`?, and I don't seem to find where is the `Socket.system_getsockopt` function?
<FromGitter>
<636f7374> Also in WSL Ubuntu (only supports Ipv4 Ethernet), `Socket.new(Ipv6Address, blocking: false)` seems to cause program hangs, CPU 100%, I don't know if it's a Crystal problem or a WSL problem.
<yxhuvud>
it is fully possible that crystal may lack some error checking and fail due to that. i'd report it to the github tracker.
<yxhuvud>
btw, doing a Pointer.new and then not assigning it to a variable will never give anything useful back as the pointer only lives during the method call.
<yxhuvud>
also, i think the error message says what is wrong, SYSPROTO_CONTROL is 2, so i think you have the argument order wrong.
<yxhuvud>
(or at least, something has that)
<yxhuvud>
or you might as well ignore everything I wrote. Hmm.
<yxhuvud>
why do C so often have weird ways of calling stuff?
<FromGitter>
<636f7374> @yxhuvud Thank you for your explanation, I am creating a TUN, and I thought it might be "argument order wrong" at first, but I wrote C bindings, and after testing, I found that it is related to `*restrict`, which made me deepen my affirmation of `*restrict`. ⏎ ⏎ 1) C.__getsockopt. ⏎ ⏎ ```cc -c lib_socket.c -o lib_socket.o ⏎ sudo crystal tun.cr``` ... [https:
<yxhuvud>
That solved it? that make me wonder why it worked at all :)
<yxhuvud>
(ie, why isn't it sending the pointer of the size in the base implementation)
<yxhuvud>
oh, I was reading the setsockopt code. wtf.
<FromGitter>
<636f7374> @yxhuvud 99% probably because I'm a rookie in C language 😣, 1% probably because I learned Crystal language from Ruby 😆.
<yxhuvud>
nah, I'm also a rookie in C :/
<FromGitter>
<636f7374> @yxhuvud 😋, Another problem I have is WSL subsystem (Ubuntu), TCPSocket.new Ipv6 blocking: false causes the program to get stuck (CPU 99%).
<yxhuvud>
my guess is that there is a errno check that isn't happening or is doing the wrong thing in some place.
<FromGitter>
<636f7374> This question is very interesting, I was using ISP & Ethernet that supports Ipv6 for the past few months, the program has been working fine, I switched to another ISP & Ethernet (Ipv4 only) this week, and then this problem was triggered, I don't Know if it's a WSL problem or a Crystal problem.
<FromGitter>
<636f7374> In the end, I regret that I did not find the answer to the problem of Ipv6 stuck. It seems that this problem has also appeared in UserLAnd & Termux AArch64 (not sure), I can only let my friends test as many commands as possible, so that there will be more discoveries in the future. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=630a812e6837563d1ca0cd01]
<xyhuvud>
I'd file an issue about it. Perhaps someone is able to replicate and figure it out
<xyhuvud>
though actually. Does dtrace work on wsl?
<xyhuvud>
argh. strace I mean. sorry.
<FromGitter>
<636f7374> I don't know if it's Crystal's problem or WSL's problem, or what problem, so I didn't submit a Github Issue, strace doesn't seem to have any clues (just a bunch of libevent-related?), because WSL doesn't have perf programs installed so it doesn't print the call stack , which leaves me a bit at a loss, but triggers this issue every time, maybe in the future? 😳
<FromGitter>
<636f7374> @xyhuvud :) Test environment requires WSL and an Ipv4-only Internet / Ethernet (The Carrier / ISP does not provide Ipv6).
<xyhuvud>
if it is not one thing its the other. personally I have issues with some work related logins because my ipv6 is too good, so it tries to use ipv6 and fails.
<FromGitter>
<636f7374> @xyhuvud Next time I try my best to let my friends install perf (it seems that WSL requires many steps to install perf) and strace information (I found only `libevent` information last time, I thought it was useless and deleted it), and I will `connect (addrinfo, timeout: connect_timeout)` inside put more `STDOUT.puts`.
<FromGitter>
<636f7374> @xyhuvud Yes, Ipv6 is not very popular in some countries. 🥲
<FromGitter>
<636f7374> @xyhuvud Cheapest ISP in my country, 5 years Broadband only cost less than 300USD, so probably no IPV6 and extremely low internet speed. 😓
sagax has joined #crystal-lang
<xyhuvud>
If you are certain it is connect that fails, system_connect may be an interesting place to put output in btw. both verifying that arguments are sane, and what errno you get.
<xyhuvud>
I have, uh, broadband as a part of my rent, but it represents something like $10 per month, for gigabit connection :)
<FromGitter>
<636f7374> @xyhuvud Okay thanks for your answer, i will do more testing next time Ipv6 stuck problem and try if it can gdb & lldb, also without your help i might just use `system_getsockopt` and not be able to find the problem Also I think `Crystal Docs / Manual` should describe `*restrict`, which is tricky for Crystal users who are not good at C language.