Since go 1.9, os.File's are backed by a mechanism similar to netpoll, whenever possible.
This means that you can set read and write deadlines on them, and that you can
safely Close() a file from another goroutine while Read and / or Write calls are active.
I'm working a lot with device nodes (/dev/XXX files, like serial ports /dev/ttySx, but
not only) and this was the best news for me. Truly godsend.
Sadly it turns out I **cannot** use this new feature, for a trivial and equally frustrating
reason:
Occasionally I need to access the underlying file-descriptor of a device in order to do
a trivial ioctl(). But if I call File.Fd(), then the underlying filedes is set to blocking mode,
and I lose (forever) all the cool poller support (deadlines, etc).
I thought I could turn the filedes to nonblocking mode myself, but this
will not do: I would also need to set internal File / pfd attributes which I have
no access to.
Alternatively, I thought I could start with a filedes (i.e. use syscall.Open) and convert
it to a file, using NewFile() (so I don't have to call File.Fd()) but again, looking at the
code, File's created with NewFile are *not* considered pollable (for reasons I do
not understand).
You can imagine my utter frustration!!
It's as if someone deliberately tried to make the feature useless and block-off any
possibility of me using it. Am I missing something? Is there a way around this in
the current state of things?
If not, please, please, please: Give me a way to get a file's underlying filedes without
setting it to non-blocking mode, and (most importantly) without loosing all the poller
goodies. It's no more than a couple of lines of code (a new method or whatever), but
without them, you 're making the situation IMPOSSIBLE for me (and, I guess for
others too). And, I believe, my case (accessing pollable device nodes) is exactly one
of those for which the poller support was added to File's for.
I could even write the code myself if you wish (it's *that* trivial) in the form of a new
method, like File.RawFd() or something...
Thanks for you attention, and sorry for the long post.
/npat