On Thu, Jun 15, 2023 at 10:41 PM akalio ja <[email protected]> wrote:
>
> GOVERSION="go1.20.3"

Thanks.  You didn't say what the exact problem was, but I would guess
that you are running into the problem described at
https://go.dev/issue/59545.  That problem should be fixed in the
upcoming 1.21 release.

Ian


> 在2023年6月15日星期四 UTC+8 23:27:43<Ian Lance Taylor> 写道:
>>
>> What version of Go are you using?
>>
>> Ian
>>
>> On Thu, Jun 15, 2023, 5:32 AM akalio ja <[email protected]> wrote:
>>>
>>> func openTun(ch chan int, timer *time.Timer) {
>>>
>>>     fd, err := unix.Open("/dev/net/tun", unix.O_RDWR|unix.O_NONBLOCK, 0)
>>>     if err != nil {
>>>         panic(err)
>>>     }
>>>     defer unix.Close(fd)
>>>
>>>     var ifr struct {
>>>         name  [16]byte
>>>         flags uint16
>>>         _     [22]byte
>>>     }
>>>     copy(ifr.name[:], "tun0")
>>>     ifr.flags = unix.IFF_TUN | unix.IFF_NO_PI
>>>     _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), 
>>> unix.TUNSETIFF, uintptr(unsafe.Pointer(&ifr)))
>>>     if errno != 0 {
>>>         log.Println("err to syscall:", errno)
>>>         return
>>>     }
>>>
>>>     ch <- fd
>>>     bytes := []byte("hell can you recv?")
>>>     fmt.Println(unix.Write(fd, bytes))
>>>
>>>     ticker := time.NewTicker(time.Second * 10)
>>>     for {
>>>         select {
>>>         case <-ticker.C:
>>>             fmt.Println(unix.Write(fd, bytes))
>>>         case <-timer.C:
>>>             return
>>>         }
>>>     }
>>> }
>>>
>>> func readFd(fd int) {
>>>
>>>     ticker := time.NewTicker(time.Second * 10)
>>>     buffer := make([]byte, 1024)
>>>     for {
>>>         <-ticker.C
>>>         n, err := unix.Read(fd, buffer)
>>>         if err != nil {
>>>             if err == unix.EAGAIN {
>>>                 log.Println("No data available at the moment")
>>>             } else {
>>>                 log.Println("Error reading from file descriptor:", err)
>>>                 return
>>>             }
>>>         } else {
>>>             log.Println("reading from file descriptor:", string(buffer[:n]))
>>>         }
>>>     }
>>> }
>>>
>>> func main() {
>>>     fdchannel, done := make(chan int, 1), time.NewTimer(time.Minute)
>>>     go openTun(fdchannel, done)
>>>     fd := <-fdchannel
>>>     log.Println("opened fd", fd)
>>>     go readFd(fd)
>>>
>>>     <- done.C
>>> }
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/4267190c-4024-48d0-b8e3-9749db9a87f9n%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/5f004bba-963d-4f3e-b5bb-e15ee43c0d2fn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXBxWSOMeM3twkV_%3D84atsNFhzuOxmjx_3QAL%2Bp6soO8g%40mail.gmail.com.

Reply via email to