@@ -244,14 +244,23 @@ class StreamResource {
244244 // `*bufs` and `*count` accordingly. This is a no-op by default.
245245 // Return 0 for success and a libuv error code for failures.
246246 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+ //
249+ // On an immediate failure, a libuv error code is returned,
250+ // req_wrap->Done() will never be called and caller should free `bufs`.
251+ //
252+ // Otherwise, 0 is returned and req_wrap->Done(status) will be called
253+ // with status set to either
254+ // (1) 0 after all data are written, or
255+ // (2) a libuv error code when an error occurs
256+ // in either case, req_wrap->Done() will never be called before DoWrite()
257+ // returns.
258+ //
259+ // When 0 is returned:
260+ // (1) memory specified by `bufs` and `count` must remain valid until
261+ // req_wrap->Done() gets called.
262+ // (2) `bufs` might or might not be changed, caller should not rely on this.
263+ // (3) `bufs` should be freed after req_wrap->Done() gets called.
255264 virtual int DoWrite (WriteWrap* w,
256265 uv_buf_t * bufs,
257266 size_t count,
@@ -343,13 +352,17 @@ class StreamBase : public StreamResource {
343352 // WriteWrap object (that was created in JS), or a new one will be created.
344353 // This will first try to write synchronously using `DoTryWrite()`, then
345354 // asynchronously using `DoWrite()`.
355+ // Caller can pass `skip_try_write` as true if it has already called
356+ // `DoTryWrite()` and ends up with a partial write, or it knows that the
357+ // write is too large to finish synchronously.
346358 // If the return value indicates a synchronous completion, no callback will
347359 // be invoked.
348360 inline StreamWriteResult Write (
349361 uv_buf_t * bufs,
350362 size_t count,
351363 uv_stream_t * send_handle = nullptr ,
352- v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>());
364+ v8::Local<v8::Object> req_wrap_obj = v8::Local<v8::Object>(),
365+ bool skip_try_write = false);
353366
354367 // These can be overridden by subclasses to get more specific wrap instances.
355368 // For example, a subclass Foo could create a FooWriteWrap or FooShutdownWrap
0 commit comments