Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: make ReqWrap req_ member private #8532

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
hints.ai_flags = flags;

int err = uv_getaddrinfo(env->event_loop(),
&req_wrap->req_,
req_wrap->req(),
AfterGetAddrInfo,
*hostname,
nullptr,
Expand Down Expand Up @@ -1176,7 +1176,7 @@ static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
GetNameInfoReqWrap* req_wrap = new GetNameInfoReqWrap(env, req_wrap_obj);

int err = uv_getnameinfo(env->event_loop(),
&req_wrap->req_,
req_wrap->req(),
AfterGetNameInfo,
(struct sockaddr*)&addr,
NI_NAMEREQD);
Expand Down
18 changes: 9 additions & 9 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static inline bool IsInt64(double x) {

static void After(uv_fs_t *req) {
FSReqWrap* req_wrap = static_cast<FSReqWrap*>(req->data);
CHECK_EQ(&req_wrap->req_, req);
CHECK_EQ(req_wrap->req(), req);
req_wrap->ReleaseEarly(); // Free memory that's no longer used now.

Environment* env = req_wrap->env();
Expand Down Expand Up @@ -320,7 +320,7 @@ static void After(uv_fs_t *req) {

req_wrap->MakeCallback(env->oncomplete_string(), argc, argv);

uv_fs_req_cleanup(&req_wrap->req_);
uv_fs_req_cleanup(req_wrap->req());
req_wrap->Dispose();
}

Expand All @@ -337,18 +337,18 @@ class fs_req_wrap {
};


#define ASYNC_DEST_CALL(func, req, dest, encoding, ...) \
#define ASYNC_DEST_CALL(func, request, dest, encoding, ...) \
Environment* env = Environment::GetCurrent(args); \
CHECK(req->IsObject()); \
FSReqWrap* req_wrap = FSReqWrap::New(env, req.As<Object>(), \
CHECK(request->IsObject()); \
FSReqWrap* req_wrap = FSReqWrap::New(env, request.As<Object>(), \
#func, dest, encoding); \
int err = uv_fs_ ## func(env->event_loop(), \
&req_wrap->req_, \
req_wrap->req(), \
__VA_ARGS__, \
After); \
req_wrap->Dispatched(); \
if (err < 0) { \
uv_fs_t* uv_req = &req_wrap->req_; \
uv_fs_t* uv_req = req_wrap->req(); \
uv_req->result = err; \
uv_req->path = nullptr; \
After(uv_req); \
Expand Down Expand Up @@ -1164,15 +1164,15 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
FSReqWrap* req_wrap =
FSReqWrap::New(env, req.As<Object>(), "write", buf, UTF8, ownership);
int err = uv_fs_write(env->event_loop(),
&req_wrap->req_,
req_wrap->req(),
fd,
&uvbuf,
1,
pos,
After);
req_wrap->Dispatched();
if (err < 0) {
uv_fs_t* uv_req = &req_wrap->req_;
uv_fs_t* uv_req = req_wrap->req();
uv_req->result = err;
uv_req->path = nullptr;
After(uv_req);
Expand Down
2 changes: 1 addition & 1 deletion src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {

ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
uv_pipe_connect(&req_wrap->req_,
uv_pipe_connect(req_wrap->req(),
&wrap->handle_,
*name,
AfterConnect);
Expand Down
10 changes: 8 additions & 2 deletions src/req-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ class ReqWrap : public AsyncWrap {
AsyncWrap::ProviderType provider);
inline ~ReqWrap() override;
inline void Dispatched(); // Call this after the req has been dispatched.
T* req() { return &req_; }

private:
friend class Environment;
ListNode<ReqWrap> req_wrap_queue_;

public:
T req_; // Must be last. TODO(bnoordhuis) Make private.
protected:
// req_wrap_queue_ needs to be at a fixed offset from the start of the class
// because it is used by ContainerOf to calculate the address of the embedding
// ReqWrap. ContainerOf compiles down to simple, fixed pointer arithmetic.
// sizeof(req_) depends on the type of T, so req_wrap_queue_ would
// no longer be at a fixed offset if it came after req_.
T req_;
};

} // namespace node
Expand Down
9 changes: 9 additions & 0 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "req-wrap.h"
#include "req-wrap-inl.h"
#include "node.h"
#include "util.h"

#include "v8.h"

Expand Down Expand Up @@ -56,6 +57,10 @@ class ShutdownWrap : public ReqWrap<uv_shutdown_t>,
CHECK(args.IsConstructCall());
}

static ShutdownWrap* from_req(uv_shutdown_t* req) {
return ContainerOf(&ShutdownWrap::req_, req);
}

inline StreamBase* wrap() const { return wrap_; }
size_t self_size() const override { return sizeof(*this); }

Expand All @@ -82,6 +87,10 @@ class WriteWrap: public ReqWrap<uv_write_t>,
CHECK(args.IsConstructCall());
}

static WriteWrap* from_req(uv_write_t* req) {
return ContainerOf(&WriteWrap::req_, req);
}

static const size_t kAlignSize = 16;

protected:
Expand Down
12 changes: 7 additions & 5 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@ void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) {

int StreamWrap::DoShutdown(ShutdownWrap* req_wrap) {
int err;
err = uv_shutdown(&req_wrap->req_, stream(), AfterShutdown);
err = uv_shutdown(req_wrap->req(), stream(), AfterShutdown);
req_wrap->Dispatched();
return err;
}


void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
ShutdownWrap* req_wrap = ContainerOf(&ShutdownWrap::req_, req);
ShutdownWrap* req_wrap = ShutdownWrap::from_req(req);
CHECK_NE(req_wrap, nullptr);
HandleScope scope(req_wrap->env()->isolate());
Context::Scope context_scope(req_wrap->env()->context());
req_wrap->Done(status);
Expand Down Expand Up @@ -336,9 +337,9 @@ int StreamWrap::DoWrite(WriteWrap* w,
uv_stream_t* send_handle) {
int r;
if (send_handle == nullptr) {
r = uv_write(&w->req_, stream(), bufs, count, AfterWrite);
r = uv_write(w->req(), stream(), bufs, count, AfterWrite);
} else {
r = uv_write2(&w->req_, stream(), bufs, count, send_handle, AfterWrite);
r = uv_write2(w->req(), stream(), bufs, count, send_handle, AfterWrite);
}

if (!r) {
Expand All @@ -360,7 +361,8 @@ int StreamWrap::DoWrite(WriteWrap* w,


void StreamWrap::AfterWrite(uv_write_t* req, int status) {
WriteWrap* req_wrap = ContainerOf(&WriteWrap::req_, req);
WriteWrap* req_wrap = WriteWrap::from_req(req);
CHECK_NE(req_wrap, nullptr);
HandleScope scope(req_wrap->env()->isolate());
Context::Scope context_scope(req_wrap->env()->context());
req_wrap->Done(status);
Expand Down
4 changes: 2 additions & 2 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
if (err == 0) {
ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
err = uv_tcp_connect(&req_wrap->req_,
err = uv_tcp_connect(req_wrap->req(),
&wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr),
AfterConnect);
Expand Down Expand Up @@ -292,7 +292,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
if (err == 0) {
ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP);
err = uv_tcp_connect(&req_wrap->req_,
err = uv_tcp_connect(req_wrap->req(),
&wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr),
AfterConnect);
Expand Down
2 changes: 1 addition & 1 deletion src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
}

if (err == 0) {
err = uv_udp_send(&req_wrap->req_,
err = uv_udp_send(req_wrap->req(),
&wrap->handle_,
*bufs,
count,
Expand Down