| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c412150 commit f734b3e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2219,6 +2219,11 @@ ssize_t Http2Stream::Provider::Stream::OnRead(nghttp2_session* handle, | |||
| 2219 | 2219 | if (amount == 0 && stream->IsWritable()) { | |
| 2220 | 2220 | CHECK(stream->queue_.empty()); | |
| 2221 | 2221 | DEBUG_HTTP2SESSION2(session, "deferring stream %d", id); | |
| 2222 | + stream->EmitWantsWrite(length); | ||
| 2223 | + if (stream->available_outbound_length_ > 0 || !stream->IsWritable()) { | ||
| 2224 | + // EmitWantsWrite() did something interesting synchronously, restart: | ||
| 2225 | + return OnRead(handle, id, buf, length, flags, source, user_data); | ||
| 2226 | + } | ||
| 2222 | 2227 | return NGHTTP2_ERR_DEFERRED; | |
| 2223 | 2228 | } | |
| 2224 | 2229 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -573,6 +573,8 @@ class Http2Stream : public AsyncWrap, | |||
| 573 | 573 | // Required for StreamBase | |
| 574 | 574 | int DoShutdown(ShutdownWrap* req_wrap) override; | |
| 575 | 575 | ||
| 576 | + bool HasWantsWrite() const override { return true; } | ||
| 577 | + | ||
| 576 | 578 | // Initiate a response on this stream. | |
| 577 | 579 | inline int SubmitResponse(nghttp2_nv* nva, | |
| 578 | 580 | size_t len, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,6 +136,13 @@ inline void StreamResource::EmitAfterShutdown(ShutdownWrap* w, int status) { | |||
| 136 | 136 | listener_->OnStreamAfterShutdown(w, status); | |
| 137 | 137 | } | |
| 138 | 138 | ||
| 139 | + inline void StreamResource::EmitWantsWrite(size_t suggested_size) { | ||
| 140 | + #ifdef DEBUG | ||
| 141 | + v8::SealHandleScope handle_scope(v8::Isolate::GetCurrent()); | ||
| 142 | + #endif | ||
| 143 | + listener_->OnStreamWantsWrite(suggested_size); | ||
| 144 | + } | ||
| 145 | + | ||
| 139 | 146 | inline StreamBase::StreamBase(Environment* env) : env_(env) { | |
| 140 | 147 | PushStreamListener(&default_listener_); | |
| 141 | 148 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,6 +131,13 @@ class StreamListener { | |||
| 131 | 131 | // (and raises an assertion if there is none). | |
| 132 | 132 | virtual void OnStreamAfterShutdown(ShutdownWrap* w, int status); | |
| 133 | 133 | ||
| 134 | + // This is called by the stream if it determines that it wants more data | ||
| 135 | + // to be written to it. Not all streams support this. | ||
| 136 | + // This callback will not be called as long as there are active writes. | ||
| 137 | + // It is not supported by all streams; `stream->HasWantsWrite()` returns | ||
| 138 | + // true if it is supported by a stream. | ||
| 139 | + virtual void OnStreamWantsWrite(size_t suggested_size) {} | ||
| 140 | + | ||
| 134 | 141 | // This is called immediately before the stream is destroyed. | |
| 135 | 142 | virtual void OnStreamDestroy() {} | |
| 136 | 143 | ||
@@ -199,6 +206,9 @@ class StreamResource { | |||
| 199 | 206 | size_t count, | |
| 200 | 207 | uv_stream_t* send_handle) = 0; | |
| 201 | 208 | ||
| 209 | + // Returns true if the stream supports the `OnStreamWantsWrite()` interface. | ||
| 210 | + virtual bool HasWantsWrite() const { return false; } | ||
| 211 | + | ||
| 202 | 212 | // Optionally, this may provide an error message to be used for | |
| 203 | 213 | // failing writes. | |
| 204 | 214 | virtual const char* Error() const; | |
@@ -222,6 +232,8 @@ class StreamResource { | |||
| 222 | 232 | void EmitAfterWrite(WriteWrap* w, int status); | |
| 223 | 233 | // Call the current listener's OnStreamAfterShutdown() method. | |
| 224 | 234 | void EmitAfterShutdown(ShutdownWrap* w, int status); | |
| 235 | + // Call the current listener's OnStreamWantsWrite() method. | ||
| 236 | + void EmitWantsWrite(size_t suggested_size); | ||
| 225 | 237 | ||
| 226 | 238 | StreamListener* listener_ = nullptr; | |
| 227 | 239 | uint64_t bytes_read_ = 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments