Skip to content

Commit

Permalink
src: use available ReqWrap instance for libuv req
Browse files Browse the repository at this point in the history
Use available `ReqWrap` descendant to make call to libuv -- avoid doing
call with the `ReqWrap`'s request member and then calling `Dispatched()`
afterwards.

PR-URL: #21980
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
maclover7 authored and targos committed Jul 31, 2018
1 parent ce527d9 commit 2f3a28d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1552,9 +1552,12 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
len = StringBytes::Write(env->isolate(), *stack_buffer, len, args[1], enc);
stack_buffer.SetLengthAndZeroTerminate(len);
uv_buf_t uvbuf = uv_buf_init(*stack_buffer, len);
int err = uv_fs_write(env->event_loop(), req_wrap_async->req(),
fd, &uvbuf, 1, pos, AfterInteger);
req_wrap_async->Dispatched();
int err = req_wrap_async->Dispatch(uv_fs_write,
fd,
&uvbuf,
1,
pos,
AfterInteger);
if (err < 0) {
uv_fs_t* uv_req = req_wrap_async->req();
uv_req->result = err;
Expand Down
16 changes: 8 additions & 8 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ WriteWrap* LibuvStreamWrap::CreateWriteWrap(Local<Object> object) {

int LibuvStreamWrap::DoShutdown(ShutdownWrap* req_wrap_) {
LibuvShutdownWrap* req_wrap = static_cast<LibuvShutdownWrap*>(req_wrap_);
int err;
err = uv_shutdown(req_wrap->req(), stream(), AfterUvShutdown);
req_wrap->Dispatched();
return err;
return req_wrap->Dispatch(uv_shutdown, stream(), AfterUvShutdown);
}


Expand Down Expand Up @@ -340,9 +337,14 @@ int LibuvStreamWrap::DoWrite(WriteWrap* req_wrap,
LibuvWriteWrap* w = static_cast<LibuvWriteWrap*>(req_wrap);
int r;
if (send_handle == nullptr) {
r = uv_write(w->req(), stream(), bufs, count, AfterUvWrite);
r = w->Dispatch(uv_write, stream(), bufs, count, AfterUvWrite);
} else {
r = uv_write2(w->req(), stream(), bufs, count, send_handle, AfterUvWrite);
r = w->Dispatch(uv_write2,
stream(),
bufs,
count,
send_handle,
AfterUvWrite);
}

if (!r) {
Expand All @@ -356,8 +358,6 @@ int LibuvStreamWrap::DoWrite(WriteWrap* req_wrap,
}
}

w->Dispatched();

return r;
}

Expand Down

0 comments on commit 2f3a28d

Please sign in to comment.