--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Tue, Nov 18, 2014 at 8:10 AM, Manlio Perillo
<manlio....@gmail.com> wrote:
>
> For a project I'm working on I need a simple level-triggered poller, since I
> only need to poll a single file descriptor from a single goroutine.
The usual approach in Go is to use a simple goroutine that reads from
the file and writes to a channel. Then you can use the select
statement to check the channel when appropriate. It's unusual to want
to use the poll or select system calls since the language gives you
other ways to do the same thing.
You can take a look at http://github.com/creack/goselect. It is a work in progress, but it gives you the idea. It supports almost all platforms.
You can take a look at http://github.com/creack/goselect. It is a work in progress, but it gives you the idea. It supports almost all platforms.
Il giorno martedì 18 novembre 2014 17:56:58 UTC+1, Guillaume J. Charmes ha scritto:You can take a look at http://github.com/creack/goselect. It is a work in progress, but it gives you the idea. It supports almost all platforms.Note that POSIX IMHO requires that NFDBITS is equal to CHAR_BIT * sizeof(long), and CHAR_BIT is always 8 on POSIX.Unfortunately, in Go you can't take the size of a type, as a constant expression.
You can take a look at fdset_doc.go, there is the original code for the different os/arch, they all do `#define __NFDBITS (sizeof(__fd_mask) * 8)`.--
--
Interesting implementation, but I'd rather stay away from unsafe. Would be interesting to benchmark though.
This will work *only* on linux. It will not compile on other platform because of the syscall.Select prototype. Only linux return two values. All others return only one.
You talk about solaris, however, there is no `syscall.Select` nor `syscall.SYS_SELECT` for Solaris in Go (even though there is a `syscall.FdSet`). If you find a way, I'd be interested.
You talk about the netbsd limitation to 256 fds, however, the code does not enforce it.
It also does not uses an int32.
I updated my version with the int32, will work on the 256 limit later.I don't think it is possible to deal with this without build tags. Any suggestions?
Minor detail questions/remarks:- Most function in the Go stdlin that deal with Fds take and return uintptr, why use int?
- Why declare a variable for the mask?
- I know that we are dealing with C consts, but Go does not like allcap/underscore ;)