问题
I have the following Golang code that seems to be blocking indefinitely
eagi := os.NewFile(uintptr(3), "/dev/stdeagi")
data := bufio.NewReaderSize(eagi, 64*1024)
...
data.WriteTo(conn) // Blocks indefinitely!
It doesn't even seem to throw an error - my guess is, I'm accessing the FD incorrectly. My purpose is to access the Process' FD 3 for Asterisk EAGI. I have also tried reading the alternative path fmt.Sprintf("/proc/%d/fd/3", os.Getpid())
, but this seems to behave the same way. What am I doing wrong?
回答1:
The right way to do this is syscall.Read(fd int, buf []byte) (n int, err error)
(doc). As regards my issue, from inside the Asterisk console, a call to sip show channelstats
showed that I wasn't receiving RTP packets altogether, and that the Read was blocking because there really was nothing to read. My networking setup needed work.
来源:https://stackoverflow.com/questions/43353694/accessing-fd-3-for-asterisk-eagi