Make DataWriter flush its own buffers, possibly on a timer, possibly after circuitmux/KIST
After a long discussion on #786 (closed), I think we concluded that bytes written to DataWriter
should get flushed eventually, even if nobody calls flush()
on the DataWriter
. This will make it easier to drop in our DataWriter
in place of other AsyncWriter
implementations that expect this kind of behavior, and make our copy_interactive
implementation unnecessary.
Okay, so when should we flush?
We probably don't want write()
to flush immediately, since doing so would needlessly create a bunch of mostly empty cells. We might want to apply something like Nagle's algorithm here (though Nagle's algorithm itself is dependent TCP details that we might not share).
Another approach we could take is to flush in a way that is partially aware of circuit and channel fullness. When we finally implement circuitmux and kist-lite cell orchestrators, we'll know when a channel is under-used, when a circuit is ready to write something, and which streams a circuit would like to read from. Then we could get more of a pull-based mechanism based on what's ready to write, and we wouldn't need to flush at all.
And when should we implement this?
That I'm not so certain of. It might be a fine idea to implement an easy version of this (not aware of circuit state) so that we can get our interface's behavior more like what users expect, and throw away copy_interactive
. On the other hand, if it would be a lot of effort, we shouldn't do that, and we should just wait till the time is right to do the hard thing.