You could also take a look 
at https://godoc.org/github.com/mailru/easygo/netpoll

четверг, 17 мая 2018 г., 3:08:29 UTC+3 пользователь Juliusz Chroboczek 
написал:
>
> I'm interfacing with a C library that expects to do its own I/O, but 
> wants to be called after a file descriptor is ready for read.  My code 
> currently looks roughly like this: 
>
>     var fdset syscall.FdSet 
>     var bits = unsafe.Sizeof(fdset.Bits[0]) * 8 
>     fdset.Bits[uintptr(fd)/bits] |= (1 << (fd % bits)) 
>     var ctv C.struct_timeval 
>     C.gettimeout(&ctv) 
>     tv := syscall.Timeval{int64(ctv.tv_sec), int64(ctv.tv_usec)} 
>     n, err := syscall.Select(int(fd + 1), &fdset, nil, nil, &tv) 
>     if n < 0 { 
>             return err 
>     } 
>     rc, err := C.dostuff(fd) 
>     if(rc < 0) { 
>             return err 
>     } 
>
> I'm bothered by two things: 
>
>   - the way I access the syscall.FdSet feels like an unportable hack; 
>   - I'd much rather hook into Go's scheduler then burn a thread on 
>     sleeping in select. 
>
> Is the above the correct way to interface with the C library, or is 
> there a better way? 
>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to