in reply to Socket descriptor passed across fork -- hanging
Okay, non-blocking IO gives me an error, errno == EAGAIN, when no data is available. So then I can loop and busy-wait on data becoming available? Ick! So I put in a usleep(10), and that dropped the CPU use from 100% to 0% while waiting for input, which seems like it's low enough to not bother about too much (dozens of clients, remember; if it were thousands I might have to work harder). So this works in my test code, and it seems to work in my real code as well (test cases running as I type).
The other choice is select(), but select requires sysread rather than ordinary read, meaning I'd have to do my own buffering implementation for the cases where I have to read line-oriented data. That might be the solution if I needed to support thousands of clients, though, it'd probably waste less cpu horsepower than my usleep(10) does.
This should be core perl territory, and I feel like I'm struggling quite a lot due to the environment not making it easy. Am I missing a better way? Or do I just have to do this over and over until it becomes simple and comfortable in my head?
The documentation could have saved me days of annoyance by being a bit clearer about how read() behaves.
|
|---|