4 ms·
It's more intuitive in the sense that you just do: while (read(...)) { ... } instead of: if (read(...) == EWOULDBLOCK) { yield();
by ww520 16y ago
It's more intuitive in the sense that you just do:
while (read(...)) {
...
}
instead of:
if (read(...) == EWOULDBLOCK) {
yield();
} else {
manage buffer
}
- Twisol 16y agoThis can be mitigated pretty well by a good library, EventMachine for example. It handles the evented complexities for you, all you need do is provide an event source and a callback.
- crux_ 16y agoDon't forget you need to make sure your callback doesn't itself block, or take too long. (Which in turn implies that all the other libraries you are using --at least ones that need to communicate-- need to have pretty deep integration with your "good library," or you're going to be writing that integration yourself.) (Not that threading is immune here... you need to be careful choosing libraries such that they are re-entrant, etc. But threading has held more mindshare for much longer, and most OSes share a roughly similar model, so they have a large head start on this front.)
- tptacek 16y agoReal event code never looks like this. You get a callback on read-readiness. You read as much as you can into a buffer. You split the buffer into requests. You act on each request. Only a tiny bit of your code ever touches send/recv. It never gets EWOULDBLOCK (it's only running because select told it to!). Most of your code deals with entire requests; the state it's saving is largely identical to what a sychronous server deals with; the overhead is in having to hot-potato it through multiple functions.