3 ms·
What's the footgun with edge triggering?
by dataflow 1y ago
What's the footgun with edge triggering?
- buckle8017 1y agoThe edge in epoll edge triggering is going from has data to doesn't have data. So the obvious loop using level triggering switched to edge will eventually lock up. You'll read 4092bbytesbwhen there is 4093 bytes leaving 1 behind and then never get a signal again.
- HackerThemAll 1y agoThis is a blatant application bug, not an epoll issue, unless you prove otherwise.
- ahartmetz 1y agoIt is a very, very easy mistake to make though. Nothing except edge-triggered I/O multiplexing makes it a problem not to read everything you possibly could, and it is often convenient to read less and let some other part of the code handle the rest. Forgot to call that part somehow? Oops, I/O on that socket is now screwed forever.
- nly 1y agoYou just read() until it returns EWOULDBLOCK/EAGAIN before calling epoll_wait again. It's no less valid than level-triggering as a default mental model.
- ahartmetz 1y agoIt's valid, just very error-prone. An advantage of the readiness model of doing I/O over the IOCP/io_uring model is that you keep control over when, where and how much data you read. If you always have to read everything, that advantage is greatly reduced. You still have a little more control and easier memory management. Performance is generally worse vs IOCP - you should at least get some convenience for it!