summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2014-01-20 13:33:16 -0800
committerTrevor Norris <trev.norris@gmail.com>2014-02-05 13:30:56 -0800
commit4a9af3fecb4baf677f265e2e6e34a674a53810a6 (patch)
tree3e96cf57bc7f9d47ebe7a177acc7a2d18dc13bdd
parentc9abb59638bc4bc64176ded80ebdc05d066ad0db (diff)
downloadnode-new-4a9af3fecb4baf677f265e2e6e34a674a53810a6.tar.gz
async_wrap: add provider types/pass to constructor
These will be used to allow users to filter for which types of calls they wish their callbacks to run. Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
-rw-r--r--src/async-wrap-inl.h14
-rw-r--r--src/async-wrap.h30
-rw-r--r--src/cares_wrap.cc7
-rw-r--r--src/fs_event_wrap.cc5
-rw-r--r--src/handle_wrap.cc5
-rw-r--r--src/handle_wrap.h3
-rw-r--r--src/node_crypto.cc4
-rw-r--r--src/node_crypto.h4
-rw-r--r--src/node_stat_watcher.cc2
-rw-r--r--src/node_zlib.cc2
-rw-r--r--src/pipe_wrap.cc9
-rw-r--r--src/process_wrap.cc5
-rw-r--r--src/req_wrap.h6
-rw-r--r--src/signal_wrap.cc5
-rw-r--r--src/stream_wrap.cc9
-rw-r--r--src/stream_wrap.h5
-rw-r--r--src/tcp_wrap.cc13
-rw-r--r--src/timer_wrap.cc5
-rw-r--r--src/tls_wrap.cc4
-rw-r--r--src/tty_wrap.cc5
-rw-r--r--src/udp_wrap.cc5
21 files changed, 109 insertions, 38 deletions
diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h
index aad1dcb3bb..388ee19c2b 100644
--- a/src/async-wrap-inl.h
+++ b/src/async-wrap-inl.h
@@ -35,9 +35,12 @@
namespace node {
-inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
+inline AsyncWrap::AsyncWrap(Environment* env,
+ v8::Handle<v8::Object> object,
+ ProviderType provider)
: BaseObject(env, object),
- async_flags_(NO_OPTIONS) {
+ async_flags_(NO_OPTIONS),
+ provider_type_(provider) {
if (!env->has_async_listener())
return;
@@ -56,14 +59,13 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
inline AsyncWrap::~AsyncWrap() {
}
-
-inline uint32_t AsyncWrap::async_flags() const {
- return async_flags_;
+inline uint32_t AsyncWrap::provider_type() const {
+ return provider_type_;
}
inline bool AsyncWrap::has_async_listener() {
- return async_flags() & HAS_ASYNC_LISTENER;
+ return async_flags_ & HAS_ASYNC_LISTENER;
}
diff --git a/src/async-wrap.h b/src/async-wrap.h
index a58031bb88..3f48290ed8 100644
--- a/src/async-wrap.h
+++ b/src/async-wrap.h
@@ -35,14 +35,37 @@ class AsyncWrap : public BaseObject {
HAS_ASYNC_LISTENER = 1
};
- inline AsyncWrap(Environment* env, v8::Handle<v8::Object> object);
+ enum ProviderType {
+ PROVIDER_NONE = 1 << 0,
+ PROVIDER_CARES = 1 << 1,
+ PROVIDER_CONNECTWRAP = 1 << 2,
+ PROVIDER_CRYPTO = 1 << 3,
+ PROVIDER_FSEVENTWRAP = 1 << 4,
+ PROVIDER_GETADDRINFOREQWRAP = 1 << 5,
+ PROVIDER_PIPEWRAP = 1 << 6,
+ PROVIDER_PROCESSWRAP = 1 << 7,
+ PROVIDER_REQWRAP = 1 << 8,
+ PROVIDER_SHUTDOWNWRAP = 1 << 9,
+ PROVIDER_SIGNALWRAP = 1 << 10,
+ PROVIDER_STATWATCHER = 1 << 11,
+ PROVIDER_TCPWRAP = 1 << 12,
+ PROVIDER_TIMERWRAP = 1 << 13,
+ PROVIDER_TLSWRAP = 1 << 14,
+ PROVIDER_TTYWRAP = 1 << 15,
+ PROVIDER_UDPWRAP = 1 << 16,
+ PROVIDER_ZLIB = 1 << 17
+ };
- inline ~AsyncWrap();
+ inline AsyncWrap(Environment* env,
+ v8::Handle<v8::Object> object,
+ ProviderType provider);
- inline uint32_t async_flags() const;
+ inline ~AsyncWrap();
inline bool has_async_listener();
+ inline uint32_t provider_type() const;
+
// Only call these within a valid HandleScope.
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
int argc,
@@ -65,6 +88,7 @@ class AsyncWrap : public BaseObject {
v8::Handle<v8::Value>* argv);
uint32_t async_flags_;
+ uint32_t provider_type_;
};
} // namespace node
diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc
index bc59513d1b..558d6d5872 100644
--- a/src/cares_wrap.cc
+++ b/src/cares_wrap.cc
@@ -224,7 +224,7 @@ static Local<Array> HostentToNames(struct hostent* host) {
class QueryWrap : public AsyncWrap {
public:
QueryWrap(Environment* env, Local<Object> req_wrap_obj)
- : AsyncWrap(env, req_wrap_obj) {
+ : AsyncWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_CARES) {
}
virtual ~QueryWrap() {
@@ -997,7 +997,10 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
abort();
}
- GetAddrInfoReqWrap* req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj);
+ GetAddrInfoReqWrap* req_wrap =
+ new GetAddrInfoReqWrap(env,
+ req_wrap_obj,
+ AsyncWrap::PROVIDER_GETADDRINFOREQWRAP);
struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo));
diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc
index 3a3559cf8a..28b20ac47c 100644
--- a/src/fs_event_wrap.cc
+++ b/src/fs_event_wrap.cc
@@ -65,7 +65,10 @@ class FSEventWrap: public HandleWrap {
FSEventWrap::FSEventWrap(Environment* env, Handle<Object> object)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&handle_)) {
+ : HandleWrap(env,
+ object,
+ reinterpret_cast<uv_handle_t*>(&handle_),
+ AsyncWrap::PROVIDER_FSEVENTWRAP) {
initialized_ = false;
}
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc
index 0a7f7d27a7..b7ee48da18 100644
--- a/src/handle_wrap.cc
+++ b/src/handle_wrap.cc
@@ -90,8 +90,9 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap::HandleWrap(Environment* env,
Handle<Object> object,
- uv_handle_t* handle)
- : AsyncWrap(env, object),
+ uv_handle_t* handle,
+ AsyncWrap::ProviderType provider)
+ : AsyncWrap(env, object, provider),
flags_(0),
handle__(handle) {
handle__->data = this;
diff --git a/src/handle_wrap.h b/src/handle_wrap.h
index 47cc44f910..910432ab84 100644
--- a/src/handle_wrap.h
+++ b/src/handle_wrap.h
@@ -62,7 +62,8 @@ class HandleWrap : public AsyncWrap {
protected:
HandleWrap(Environment* env,
v8::Handle<v8::Object> object,
- uv_handle_t* handle);
+ uv_handle_t* handle,
+ AsyncWrap::ProviderType provider);
virtual ~HandleWrap();
private:
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index 9952b2c0aa..1b10301dea 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3498,7 +3498,7 @@ class PBKDF2Request : public AsyncWrap {
char* salt,
ssize_t iter,
ssize_t keylen)
- : AsyncWrap(env, object),
+ : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
digest_(digest),
error_(0),
passlen_(passlen),
@@ -3760,7 +3760,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
class RandomBytesRequest : public AsyncWrap {
public:
RandomBytesRequest(Environment* env, Local<Object> object, size_t size)
- : AsyncWrap(env, object),
+ : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
error_(0),
size_(size),
data_(static_cast<char*>(malloc(size))) {
diff --git a/src/node_crypto.h b/src/node_crypto.h
index 8e94950c14..889d270c5c 100644
--- a/src/node_crypto.h
+++ b/src/node_crypto.h
@@ -297,7 +297,7 @@ class Connection : public SSLWrap<Connection>, public AsyncWrap {
SecureContext* sc,
SSLWrap<Connection>::Kind kind)
: SSLWrap<Connection>(env, sc, kind),
- AsyncWrap(env, wrap),
+ AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO),
bio_read_(NULL),
bio_write_(NULL),
hello_offset_(0) {
@@ -583,7 +583,7 @@ class Certificate : public AsyncWrap {
static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args);
Certificate(Environment* env, v8::Local<v8::Object> wrap)
- : AsyncWrap(env, wrap) {
+ : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO) {
MakeWeak<Certificate>(this);
}
};
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index e71ca430cd..fadce4557b 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -66,7 +66,7 @@ static void Delete(uv_handle_t* handle) {
StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
- : AsyncWrap(env, wrap),
+ : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
watcher_(new uv_fs_poll_t) {
MakeWeak<StatWatcher>(this);
uv_fs_poll_init(env->event_loop(), watcher_);
diff --git a/src/node_zlib.cc b/src/node_zlib.cc
index 8a2125fa3f..31d8e830b0 100644
--- a/src/node_zlib.cc
+++ b/src/node_zlib.cc
@@ -74,7 +74,7 @@ class ZCtx : public AsyncWrap {
public:
ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode)
- : AsyncWrap(env, wrap),
+ : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_ZLIB),
chunk_size_(0),
dictionary_(NULL),
dictionary_len_(0),
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index 517d97ccb8..67a756294e 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -128,7 +128,10 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
PipeWrap::PipeWrap(Environment* env, Handle<Object> object, bool ipc)
- : StreamWrap(env, object, reinterpret_cast<uv_stream_t*>(&handle_)) {
+ : StreamWrap(env,
+ object,
+ reinterpret_cast<uv_stream_t*>(&handle_),
+ AsyncWrap::PROVIDER_PIPEWRAP) {
int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
@@ -275,7 +278,9 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
Local<Object> req_wrap_obj = args[0].As<Object>();
String::AsciiValue name(args[1]);
- ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj);
+ ConnectWrap* req_wrap = new ConnectWrap(env,
+ req_wrap_obj,
+ AsyncWrap::PROVIDER_CONNECTWRAP);
uv_pipe_connect(&req_wrap->req_,
&wrap->handle_,
*name,
diff --git a/src/process_wrap.cc b/src/process_wrap.cc
index 5592cfeaa5..f21fef9b8e 100644
--- a/src/process_wrap.cc
+++ b/src/process_wrap.cc
@@ -78,7 +78,10 @@ class ProcessWrap : public HandleWrap {
}
ProcessWrap(Environment* env, Handle<Object> object)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&process_)) {
+ : HandleWrap(env,
+ object,
+ reinterpret_cast<uv_handle_t*>(&process_),
+ AsyncWrap::PROVIDER_PROCESSWRAP) {
}
~ProcessWrap() {
diff --git a/src/req_wrap.h b/src/req_wrap.h
index 043edb2f60..304b1a49a9 100644
--- a/src/req_wrap.h
+++ b/src/req_wrap.h
@@ -37,8 +37,10 @@ extern QUEUE req_wrap_queue;
template <typename T>
class ReqWrap : public AsyncWrap {
public:
- ReqWrap(Environment* env, v8::Handle<v8::Object> object)
- : AsyncWrap(env, object) {
+ ReqWrap(Environment* env,
+ v8::Handle<v8::Object> object,
+ AsyncWrap::ProviderType provider = AsyncWrap::PROVIDER_REQWRAP)
+ : AsyncWrap(env, object, AsyncWrap::PROVIDER_REQWRAP) {
if (env->in_domain())
object->Set(env->domain_string(), env->domain_array()->Get(0));
diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc
index 74eb830aac..dbf4b949e6 100644
--- a/src/signal_wrap.cc
+++ b/src/signal_wrap.cc
@@ -72,7 +72,10 @@ class SignalWrap : public HandleWrap {
}
SignalWrap(Environment* env, Handle<Object> object)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&handle_)) {
+ : HandleWrap(env,
+ object,
+ reinterpret_cast<uv_handle_t*>(&handle_),
+ AsyncWrap::PROVIDER_SIGNALWRAP) {
int r = uv_signal_init(env->event_loop(), &handle_);
assert(r == 0);
}
diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc
index 848abefd5e..1a05945fbb 100644
--- a/src/stream_wrap.cc
+++ b/src/stream_wrap.cc
@@ -57,8 +57,9 @@ using v8::Value;
StreamWrap::StreamWrap(Environment* env,
Local<Object> object,
- uv_stream_t* stream)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(stream)),
+ uv_stream_t* stream,
+ AsyncWrap::ProviderType provider)
+ : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(stream), provider),
stream_(stream),
default_callbacks_(this),
callbacks_(&default_callbacks_) {
@@ -528,7 +529,9 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsObject());
Local<Object> req_wrap_obj = args[0].As<Object>();
- ShutdownWrap* req_wrap = new ShutdownWrap(env, req_wrap_obj);
+ ShutdownWrap* req_wrap = new ShutdownWrap(env,
+ req_wrap_obj,
+ AsyncWrap::PROVIDER_SHUTDOWNWRAP);
int err = wrap->callbacks()->DoShutdown(req_wrap, AfterShutdown);
req_wrap->Dispatched();
if (err)
diff --git a/src/stream_wrap.h b/src/stream_wrap.h
index f91bb8ba55..0f657fe920 100644
--- a/src/stream_wrap.h
+++ b/src/stream_wrap.h
@@ -37,6 +37,8 @@ typedef class ReqWrap<uv_shutdown_t> ShutdownWrap;
class WriteWrap: public ReqWrap<uv_write_t> {
public:
+ // TODO(trevnorris): WrapWrap inherits from ReqWrap, which I've globbed
+ // into the same provider. How should these be broken apart?
WriteWrap(Environment* env, v8::Local<v8::Object> obj, StreamWrap* wrap)
: ReqWrap<uv_write_t>(env, obj),
wrap_(wrap) {
@@ -150,7 +152,8 @@ class StreamWrap : public HandleWrap {
StreamWrap(Environment* env,
v8::Local<v8::Object> object,
- uv_stream_t* stream);
+ uv_stream_t* stream,
+ AsyncWrap::ProviderType provider);
~StreamWrap() {
if (callbacks_ != &default_callbacks_) {
diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc
index 99d71bffe5..728d87a698 100644
--- a/src/tcp_wrap.cc
+++ b/src/tcp_wrap.cc
@@ -139,7 +139,10 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
TCPWrap::TCPWrap(Environment* env, Handle<Object> object)
- : StreamWrap(env, object, reinterpret_cast<uv_stream_t*>(&handle_)) {
+ : StreamWrap(env,
+ object,
+ reinterpret_cast<uv_stream_t*>(&handle_),
+ AsyncWrap::PROVIDER_TCPWRAP) {
int r = uv_tcp_init(env->event_loop(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void.
@@ -377,7 +380,9 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
int err = uv_ip4_addr(*ip_address, port, &addr);
if (err == 0) {
- ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj);
+ ConnectWrap* req_wrap = new ConnectWrap(env,
+ req_wrap_obj,
+ AsyncWrap::PROVIDER_CONNECTWRAP);
err = uv_tcp_connect(&req_wrap->req_,
&wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr),
@@ -409,7 +414,9 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
int err = uv_ip6_addr(*ip_address, port, &addr);
if (err == 0) {
- ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj);
+ ConnectWrap* req_wrap = new ConnectWrap(env,
+ req_wrap_obj,
+ AsyncWrap::PROVIDER_CONNECTWRAP);
err = uv_tcp_connect(&req_wrap->req_,
&wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr),
diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc
index e82f9036d1..498bcbb846 100644
--- a/src/timer_wrap.cc
+++ b/src/timer_wrap.cc
@@ -83,7 +83,10 @@ class TimerWrap : public HandleWrap {
}
TimerWrap(Environment* env, Handle<Object> object)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&handle_)) {
+ : HandleWrap(env,
+ object,
+ reinterpret_cast<uv_handle_t*>(&handle_),
+ AsyncWrap::PROVIDER_TIMERWRAP) {
int r = uv_timer_init(env->event_loop(), &handle_);
assert(r == 0);
}
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index 4475f7b8e7..4e5b07f7d5 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -68,7 +68,9 @@ TLSCallbacks::TLSCallbacks(Environment* env,
StreamWrapCallbacks* old)
: SSLWrap<TLSCallbacks>(env, Unwrap<SecureContext>(sc), kind),
StreamWrapCallbacks(old),
- AsyncWrap(env, env->tls_wrap_constructor_function()->NewInstance()),
+ AsyncWrap(env,
+ env->tls_wrap_constructor_function()->NewInstance(),
+ AsyncWrap::PROVIDER_TLSWRAP),
sc_(Unwrap<SecureContext>(sc)),
sc_handle_(env->isolate(), sc),
enc_in_(NULL),
diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc
index b1a354ac33..4b5b8587c0 100644
--- a/src/tty_wrap.cc
+++ b/src/tty_wrap.cc
@@ -174,7 +174,10 @@ void TTYWrap::New(const FunctionCallbackInfo<Value>& args) {
TTYWrap::TTYWrap(Environment* env, Handle<Object> object, int fd, bool readable)
- : StreamWrap(env, object, reinterpret_cast<uv_stream_t*>(&handle_)) {
+ : StreamWrap(env,
+ object,
+ reinterpret_cast<uv_stream_t*>(&handle_),
+ AsyncWrap::PROVIDER_TTYWRAP) {
uv_tty_init(env->event_loop(), &handle_, fd, readable);
}
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index b5ae878dd1..7d5fd942ba 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -73,7 +73,10 @@ inline bool SendWrap::have_callback() const {
UDPWrap::UDPWrap(Environment* env, Handle<Object> object)
- : HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&handle_)) {
+ : HandleWrap(env,
+ object,
+ reinterpret_cast<uv_handle_t*>(&handle_),
+ AsyncWrap::PROVIDER_UDPWRAP) {
int r = uv_udp_init(env->event_loop(), &handle_);
assert(r == 0); // can't fail anyway
}