| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 99a2c16 commit 281fd7a
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2375,8 +2375,7 @@ int Http2Stream::DoWrite(WriteWrap* req_wrap, | |||
| 2375 | 2375 | CHECK_NULL(send_handle); | |
| 2376 | 2376 | Http2Scope h2scope(this); | |
| 2377 | 2377 | if (!is_writable() || is_destroyed()) { | |
| 2378 | - req_wrap->Done(UV_EOF); | ||
| 2379 | - return 0; | ||
| 2378 | + return UV_EOF; | ||
| 2380 | 2379 | } | |
| 2381 | 2380 | Debug(this, "queuing %d buffers to send", nbufs); | |
| 2382 | 2381 | for (size_t i = 0; i < nbufs; ++i) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,11 +160,11 @@ int StreamBase::Shutdown(v8::Local<v8::Object> req_wrap_obj) { | |||
| 160 | 160 | return err; | |
| 161 | 161 | } | |
| 162 | 162 | ||
| 163 | - StreamWriteResult StreamBase::Write( | ||
| 164 | - uv_buf_t* bufs, | ||
| 165 | - size_t count, | ||
| 166 | - uv_stream_t* send_handle, | ||
| 167 | - v8::Local<v8::Object> req_wrap_obj) { | ||
| 163 | + StreamWriteResult StreamBase::Write(uv_buf_t* bufs, | ||
| 164 | + size_t count, | ||
| 165 | + uv_stream_t* send_handle, | ||
| 166 | + v8::Local<v8::Object> req_wrap_obj, | ||
| 167 | + bool skip_try_write) { | ||
| 168 | 168 | Environment* env = stream_env(); | |
| 169 | 169 | int err; | |
| 170 | 170 | ||
@@ -173,7 +173,7 @@ StreamWriteResult StreamBase::Write( | |||
| 173 | 173 | total_bytes += bufs[i].len; | |
| 174 | 174 | bytes_written_ += total_bytes; | |
| 175 | 175 | ||
| 176 | - if (send_handle == nullptr) { | ||
| 176 | + if (send_handle == nullptr && !skip_try_write) { | ||
| 177 | 177 | err = DoTryWrite(&bufs, &count); | |
| 178 | 178 | if (err != 0 || count == 0) { | |
| 179 | 179 | return StreamWriteResult { false, err, nullptr, total_bytes, {} }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,7 +335,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) { | |||
| 335 | 335 | } | |
| 336 | 336 | } | |
| 337 | 337 | ||
| 338 | - StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); | ||
| 338 | + StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj, try_write); | ||
| 339 | 339 | res.bytes += synchronously_written; | |
| 340 | 340 | ||
| 341 | 341 | SetWriteResult(res); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -244,14 +244,19 @@ class StreamResource { | |||
| 244 | 244 | // `*bufs` and `*count` accordingly. This is a no-op by default. | |
| 245 | 245 | // Return 0 for success and a libuv error code for failures. | |
| 246 | 246 | virtual int DoTryWrite(uv_buf_t** bufs, size_t* count); | |
| 247 | - // Initiate a write of data. If the write completes synchronously, return 0 on | ||
| 248 | - // success (with bufs modified to indicate how much data was consumed) or a | ||
| 249 | - // libuv error code on failure. If the write will complete asynchronously, | ||
| 250 | - // return 0. When the write completes asynchronously, call req_wrap->Done() | ||
| 251 | - // with 0 on success (with bufs modified to indicate how much data was | ||
| 252 | - // consumed) or a libuv error code on failure. Do not call req_wrap->Done() if | ||
| 253 | - // the write completes synchronously, that is, it should never be called | ||
| 254 | - // before DoWrite() has returned. | ||
| 247 | + // Initiate a write of data. | ||
| 248 | + // Upon an immediate failure, a libuv error code is returned, | ||
| 249 | + // w->Done() will never be called and caller should free `bufs`. | ||
| 250 | + // Otherwise, 0 is returned and w->Done(status) will be called | ||
| 251 | + // with status set to either | ||
| 252 | + // (1) 0 after all data are written, or | ||
| 253 | + // (2) a libuv error code when an error occurs | ||
| 254 | + // in either case, w->Done() will never be called before DoWrite() returns. | ||
| 255 | + // When 0 is returned: | ||
| 256 | + // (1) memory specified by `bufs` and `count` must remain valid until | ||
| 257 | + // w->Done() gets called. | ||
| 258 | + // (2) `bufs` might or might not be changed, caller should not rely on this. | ||
| 259 | + // (3) `bufs` should be freed after w->Done() gets called. | ||
| 255 | 260 | virtual int DoWrite(WriteWrap* w, | |
| 256 | 261 | uv_buf_t* bufs, | |
| 257 | 262 | size_t count, | |
@@ -343,13 +348,17 @@ class StreamBase : public StreamResource { | |||
| 343 | 348 | // WriteWrap object (that was created in JS), or a new one will be created. | |
| 344 | 349 | // This will first try to write synchronously using `DoTryWrite()`, then | |
| 345 | 350 | // asynchronously using `DoWrite()`. | |
| 351 | + // Caller can pass `skip_try_write` as true if it has already called | ||
| 352 | + // `DoTryWrite()` and ends up with a partial write, or it knows that the | ||
| 353 | + // write is too large to finish synchronously. | ||
| 346 | 354 | // If the return value indicates a synchronous completion, no callback will | |
| 347 | 355 | // be invoked. | |
| 348 | 356 | inline StreamWriteResult Write( | |
| 349 | 357 | uv_buf_t* bufs, | |
| 350 | 358 | size_t count, | |
| 351 | 359 | uv_stream_t* send_handle = nullptr, | |
| 352 | - v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>()); | ||
| 360 | + v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>(), | ||
| 361 | + bool skip_try_write = false); | ||
| 353 | 362 | ||
| 354 | 363 | // These can be overridden by subclasses to get more specific wrap instances. | |
| 355 | 364 | // For example, a subclass Foo could create a FooWriteWrap or FooShutdownWrap | |
| Back | FazBrowse Home | New Git URL |
0 commit comments