Skip to content

Commit

Permalink
fs: use SyncCall in WriteBuffers
Browse files Browse the repository at this point in the history
PR-URL: #19041
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Mar 2, 2018
1 parent 49dd809 commit 80bd2da
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1320,11 +1320,15 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
static void WriteBuffers(const FunctionCallbackInfo<Value>& 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<Int32>()->Value();

int fd = args[0]->Int32Value();
CHECK(args[1]->IsArray());
Local<Array> chunks = args[1].As<Array>();

int64_t pos = GET_OFFSET(args[2]);

MaybeStackBuffer<uv_buf_t> iovs(chunks->Length());
Expand All @@ -1336,14 +1340,16 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& 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);
}


Expand Down

0 comments on commit 80bd2da

Please sign in to comment.