From 61baa455810d013ae547624e67b0c03429d341cc Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 25 Feb 2019 13:37:05 -0800 Subject: [PATCH] src: document DoWrite() usage expectations Clarify how it must behave for both synchronous and asynchronous completion. PR-URL: https://github.com/nodejs/node/pull/26339 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- src/stream_base.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/stream_base.h b/src/stream_base.h index 33cf62a0c861ba..bf15dbc91e05f0 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -207,8 +207,14 @@ class StreamResource { // `*bufs` and `*count` accordingly. This is a no-op by default. // Return 0 for success and a libuv error code for failures. virtual int DoTryWrite(uv_buf_t** bufs, size_t* count); - // Perform a write of data, and either call req_wrap->Done() when finished - // and return 0, or return a libuv error code for synchronous failures. + // Initiate a write of data. If the write completes synchronously, return 0 on + // success (with bufs modified to indicate how much data was consumed) or a + // libuv error code on failure. If the write will complete asynchronously, + // return 0. When the write completes asynchronously, call req_wrap->Done() + // with 0 on success (with bufs modified to indicate how much data was + // consumed) or a libuv error code on failure. Do not call req_wrap->Done() if + // the write completes synchronously, that is, it should never be called + // before DoWrite() has returned. virtual int DoWrite(WriteWrap* w, uv_buf_t* bufs, size_t count,