4 ms·
I'm working on a library for C++ called Team where this kind of flow control is possible. At its core it's got coroutines, so you can write code in a blocking s
by Sidnicious 13y ago
I'm working on a library for C++ called Team where this kind of flow control is possible. At its core it's got coroutines, so you can write code in a blocking style.
The current (early!) socket APIs can all be called with a callback (which act like Node and call it as fast as possible), or without one (in which case they block). Here's an echo server that accepts connections as fast as possible, but does blocking reads and writes so only one chunk per client gets buffered at a time:
https://github.com/Sidnicious/team/blob/b157ea2c58177a2587c9735f855cfbd15080d2f2/examples/echo_server.cpp https://github.com/Sidnicious/team/blob/b157ea2c58177a2587c9...
The callbacks-as-fast-as-possible version is just implemented on top of the blocking one, so it'd be trivial to add flow control via a blocking callback (or by calling `accept()` in blocking style and making your own decision about when to call it again):
https://github.com/Sidnicious/team/blob/b157ea2c58177a2587c9735f855cfbd15080d2f2/team/net.h#L119-125 https://github.com/Sidnicious/team/blob/b157ea2c58177a2587c9...