Unix select function is dangerous


We were having intermittent crashes only in situations where our application had a large number of files open. We tracked it down to usage of the select function in the JUCE socket code. The FD_SET macro will basically trash memory if the FILE descriptor value is too large. That was happening in our case once more than 1024 files were opened. Probably not common, but not that uncommon either for certain usages. If you want to read a little on this topic this article is not bad.

We replaced usage of select with poll and it seems to be working well for us. I’d recommend doing the same in JUCE. If there is interest I could send my changes over, or perhaps prepare a pull request on github.

I’ve tagged this issue as a Mac issue. The Windows implementation of FD_SET does not have this problem. I’m not sure about linux, but I’d imagine it suffers the same issue.



I’ve replaced this and a few more select calls with poll here:

Great, thanks!