evo-lua / evo-legacy

[Obsoleted Prototype] Highly experimental Lua runtime environment built on Luvi (libuv + LuaJIT)
https://evo-lua.github.io
0 stars 0 forks source link

Consider adding a backpressure buffering mechanism for failed writes to TCP sockets #71

Open rdw-software opened 2 years ago

rdw-software commented 2 years ago

The API I came up with for #61 doesn't handle backpressure from failed Write() calls. In NodeJS, the socket is automatically paused and future writes buffered, but only to a limit (called highWaterMark). The socket then emits a drain event once the empty/writes can continue.

There's no such buffering in the C_Networking API, which is a deliberate decision with the goal of simplifying the API, but that means writes can fail and the caller would have to handle it... which of course works against the goal of making the API easy to use.

Maybe the approach used by Node (and Luvit) can be implemented without the giant inheritance hierarchy of streams etc. that I wanted to avoid with the above "basic" implementation. I'll have to look into creating a test scenario (slow receiver/read from socket with timeout) and then consider if the approach can be recreated on top of simple libuv primitives, without too much accidental complexity.