From 80bd2da6e1352d4f93682181683be1ab826b9128 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 28 Feb 2018 02:36:43 +0800 Subject: [PATCH] fs: use SyncCall in WriteBuffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/19041 Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- src/node_file.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index dc9027cd5d9c9e..f25bc81d610b5a 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1320,11 +1320,15 @@ static void WriteBuffer(const FunctionCallbackInfo& args) { static void WriteBuffers(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + const int argc = args.Length(); + CHECK_GE(argc, 3); + CHECK(args[0]->IsInt32()); - CHECK(args[1]->IsArray()); + const int fd = args[0].As()->Value(); - int fd = args[0]->Int32Value(); + CHECK(args[1]->IsArray()); Local chunks = args[1].As(); + int64_t pos = GET_OFFSET(args[2]); MaybeStackBuffer iovs(chunks->Length()); @@ -1336,14 +1340,16 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { } FSReqBase* req_wrap = GetReqWrap(env, args[3]); - if (req_wrap != nullptr) { + if (req_wrap != nullptr) { // writeBuffers(fd, chunks, pos, req) AsyncCall(env, req_wrap, args, "write", UTF8, AfterInteger, uv_fs_write, fd, *iovs, iovs.length(), pos); - return; + } else { // writeBuffers(fd, chunks, pos, undefined, ctx) + CHECK_EQ(argc, 5); + fs_req_wrap req_wrap; + int bytesWritten = SyncCall(env, args[4], &req_wrap, "write", + uv_fs_write, fd, *iovs, iovs.length(), pos); + args.GetReturnValue().Set(bytesWritten); } - - SYNC_CALL(write, nullptr, fd, *iovs, iovs.length(), pos) - args.GetReturnValue().Set(SYNC_RESULT); }