Skip to content
Permalink
Browse files

src: make ReqWrap req_ member private

This commit attempts to address one of the items in
#4641 which is
related to src/req-wrap.h and making the req_ member private.

PR-URL: #8532
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
danbev authored and Fishrock123 committed Jul 24, 2016
1 parent 5c014bb commit a9491f16046a9281fe2265513b5011378879b9e3
Showing with 39 additions and 22 deletions.
  1. +2 −2 src/cares_wrap.cc
  2. +9 −9 src/node_file.cc
  3. +1 −1 src/pipe_wrap.cc
  4. +8 −2 src/req-wrap.h
  5. +9 −0 src/stream_base.h
  6. +7 −5 src/stream_wrap.cc
  7. +2 −2 src/tcp_wrap.cc
  8. +1 −1 src/udp_wrap.cc
@@ -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,
@@ -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);
@@ -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();
@@ -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();
}

@@ -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); \
@@ -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);
@@ -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);
@@ -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
@@ -8,6 +8,7 @@
#include "req-wrap.h"
#include "req-wrap-inl.h"
#include "node.h"
#include "util.h"

#include "v8.h"

@@ -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); }

@@ -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:
@@ -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);
@@ -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) {
@@ -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);
@@ -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);
@@ -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);
@@ -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,

0 comments on commit a9491f1

Please sign in to comment.
You can’t perform that action at this time.