summaryrefslogtreecommitdiff
path: root/src/stream_base.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-02-22 14:37:58 +0100
committerAnna Henningsen <anna@addaleax.net>2018-03-15 12:53:06 +0100
commitf734b3eb04c0d355ef7ab893ed5869b867d35642 (patch)
tree88950ea4877e1394e491bcfc4b9f8d217f27a0b6 /src/stream_base.h
parentc412150582de524beacd180646ec5f18c518a922 (diff)
downloadnode-new-f734b3eb04c0d355ef7ab893ed5869b867d35642.tar.gz
src: give StreamBases the capability to ask for data
Add a `OnStreamWantsWrite()` event that allows streams to ask for more input data if they want some. PR-URL: https://github.com/nodejs/node/pull/18936 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/stream_base.h')
-rw-r--r--src/stream_base.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/stream_base.h b/src/stream_base.h
index f3e010d5bc..96a7787e5b 100644
--- a/src/stream_base.h
+++ b/src/stream_base.h
@@ -131,6 +131,13 @@ class StreamListener {
// (and raises an assertion if there is none).
virtual void OnStreamAfterShutdown(ShutdownWrap* w, int status);
+ // This is called by the stream if it determines that it wants more data
+ // to be written to it. Not all streams support this.
+ // This callback will not be called as long as there are active writes.
+ // It is not supported by all streams; `stream->HasWantsWrite()` returns
+ // true if it is supported by a stream.
+ virtual void OnStreamWantsWrite(size_t suggested_size) {}
+
// This is called immediately before the stream is destroyed.
virtual void OnStreamDestroy() {}
@@ -199,6 +206,9 @@ class StreamResource {
size_t count,
uv_stream_t* send_handle) = 0;
+ // Returns true if the stream supports the `OnStreamWantsWrite()` interface.
+ virtual bool HasWantsWrite() const { return false; }
+
// Optionally, this may provide an error message to be used for
// failing writes.
virtual const char* Error() const;
@@ -222,6 +232,8 @@ class StreamResource {
void EmitAfterWrite(WriteWrap* w, int status);
// Call the current listener's OnStreamAfterShutdown() method.
void EmitAfterShutdown(ShutdownWrap* w, int status);
+ // Call the current listener's OnStreamWantsWrite() method.
+ void EmitWantsWrite(size_t suggested_size);
StreamListener* listener_ = nullptr;
uint64_t bytes_read_ = 0;