Browse Source

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>
v0.11.12-release
Trevor Norris 11 years ago
parent
commit
4a9af3fecb
  1. 14
      src/async-wrap-inl.h
  2. 30
      src/async-wrap.h
  3. 7
      src/cares_wrap.cc
  4. 5
      src/fs_event_wrap.cc
  5. 5
      src/handle_wrap.cc
  6. 3
      src/handle_wrap.h
  7. 4
      src/node_crypto.cc
  8. 4
      src/node_crypto.h
  9. 2
      src/node_stat_watcher.cc
  10. 2
      src/node_zlib.cc
  11. 9
      src/pipe_wrap.cc
  12. 5
      src/process_wrap.cc
  13. 6
      src/req_wrap.h
  14. 5
      src/signal_wrap.cc
  15. 9
      src/stream_wrap.cc
  16. 5
      src/stream_wrap.h
  17. 13
      src/tcp_wrap.cc
  18. 5
      src/timer_wrap.cc
  19. 4
      src/tls_wrap.cc
  20. 5
      src/tty_wrap.cc
  21. 5
      src/udp_wrap.cc

14
src/async-wrap-inl.h

@ -35,9 +35,12 @@
namespace node { 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), : BaseObject(env, object),
async_flags_(NO_OPTIONS) { async_flags_(NO_OPTIONS),
provider_type_(provider) {
if (!env->has_async_listener()) if (!env->has_async_listener())
return; return;
@ -56,14 +59,13 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
inline AsyncWrap::~AsyncWrap() { inline AsyncWrap::~AsyncWrap() {
} }
inline uint32_t AsyncWrap::provider_type() const {
inline uint32_t AsyncWrap::async_flags() const { return provider_type_;
return async_flags_;
} }
inline bool AsyncWrap::has_async_listener() { inline bool AsyncWrap::has_async_listener() {
return async_flags() & HAS_ASYNC_LISTENER; return async_flags_ & HAS_ASYNC_LISTENER;
} }

30
src/async-wrap.h

@ -35,14 +35,37 @@ class AsyncWrap : public BaseObject {
HAS_ASYNC_LISTENER = 1 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 bool has_async_listener();
inline uint32_t provider_type() const;
// Only call these within a valid HandleScope. // Only call these within a valid HandleScope.
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb, inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
int argc, int argc,
@ -65,6 +88,7 @@ class AsyncWrap : public BaseObject {
v8::Handle<v8::Value>* argv); v8::Handle<v8::Value>* argv);
uint32_t async_flags_; uint32_t async_flags_;
uint32_t provider_type_;
}; };
} // namespace node } // namespace node

7
src/cares_wrap.cc

@ -224,7 +224,7 @@ static Local<Array> HostentToNames(struct hostent* host) {
class QueryWrap : public AsyncWrap { class QueryWrap : public AsyncWrap {
public: public:
QueryWrap(Environment* env, Local<Object> req_wrap_obj) QueryWrap(Environment* env, Local<Object> req_wrap_obj)
: AsyncWrap(env, req_wrap_obj) { : AsyncWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_CARES) {
} }
virtual ~QueryWrap() { virtual ~QueryWrap() {
@ -997,7 +997,10 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
abort(); 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; struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));

5
src/fs_event_wrap.cc

@ -65,7 +65,10 @@ class FSEventWrap: public HandleWrap {
FSEventWrap::FSEventWrap(Environment* env, Handle<Object> object) 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; initialized_ = false;
} }

5
src/handle_wrap.cc

@ -90,8 +90,9 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap::HandleWrap(Environment* env, HandleWrap::HandleWrap(Environment* env,
Handle<Object> object, Handle<Object> object,
uv_handle_t* handle) uv_handle_t* handle,
: AsyncWrap(env, object), AsyncWrap::ProviderType provider)
: AsyncWrap(env, object, provider),
flags_(0), flags_(0),
handle__(handle) { handle__(handle) {
handle__->data = this; handle__->data = this;

3
src/handle_wrap.h

@ -62,7 +62,8 @@ class HandleWrap : public AsyncWrap {
protected: protected:
HandleWrap(Environment* env, HandleWrap(Environment* env,
v8::Handle<v8::Object> object, v8::Handle<v8::Object> object,
uv_handle_t* handle); uv_handle_t* handle,
AsyncWrap::ProviderType provider);
virtual ~HandleWrap(); virtual ~HandleWrap();
private: private:

4
src/node_crypto.cc

@ -3498,7 +3498,7 @@ class PBKDF2Request : public AsyncWrap {
char* salt, char* salt,
ssize_t iter, ssize_t iter,
ssize_t keylen) ssize_t keylen)
: AsyncWrap(env, object), : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
digest_(digest), digest_(digest),
error_(0), error_(0),
passlen_(passlen), passlen_(passlen),
@ -3760,7 +3760,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
class RandomBytesRequest : public AsyncWrap { class RandomBytesRequest : public AsyncWrap {
public: public:
RandomBytesRequest(Environment* env, Local<Object> object, size_t size) RandomBytesRequest(Environment* env, Local<Object> object, size_t size)
: AsyncWrap(env, object), : AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
error_(0), error_(0),
size_(size), size_(size),
data_(static_cast<char*>(malloc(size))) { data_(static_cast<char*>(malloc(size))) {

4
src/node_crypto.h

@ -297,7 +297,7 @@ class Connection : public SSLWrap<Connection>, public AsyncWrap {
SecureContext* sc, SecureContext* sc,
SSLWrap<Connection>::Kind kind) SSLWrap<Connection>::Kind kind)
: SSLWrap<Connection>(env, sc, kind), : SSLWrap<Connection>(env, sc, kind),
AsyncWrap(env, wrap), AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO),
bio_read_(NULL), bio_read_(NULL),
bio_write_(NULL), bio_write_(NULL),
hello_offset_(0) { hello_offset_(0) {
@ -583,7 +583,7 @@ class Certificate : public AsyncWrap {
static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args); static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args);
Certificate(Environment* env, v8::Local<v8::Object> wrap) Certificate(Environment* env, v8::Local<v8::Object> wrap)
: AsyncWrap(env, wrap) { : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO) {
MakeWeak<Certificate>(this); MakeWeak<Certificate>(this);
} }
}; };

2
src/node_stat_watcher.cc

@ -66,7 +66,7 @@ static void Delete(uv_handle_t* handle) {
StatWatcher::StatWatcher(Environment* env, Local<Object> wrap) StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
: AsyncWrap(env, wrap), : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
watcher_(new uv_fs_poll_t) { watcher_(new uv_fs_poll_t) {
MakeWeak<StatWatcher>(this); MakeWeak<StatWatcher>(this);
uv_fs_poll_init(env->event_loop(), watcher_); uv_fs_poll_init(env->event_loop(), watcher_);

2
src/node_zlib.cc

@ -74,7 +74,7 @@ class ZCtx : public AsyncWrap {
public: public:
ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode) ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode)
: AsyncWrap(env, wrap), : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_ZLIB),
chunk_size_(0), chunk_size_(0),
dictionary_(NULL), dictionary_(NULL),
dictionary_len_(0), dictionary_len_(0),

9
src/pipe_wrap.cc

@ -128,7 +128,10 @@ void PipeWrap::New(const FunctionCallbackInfo<Value>& args) {
PipeWrap::PipeWrap(Environment* env, Handle<Object> object, bool ipc) 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); int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
assert(r == 0); // How do we proxy this error up to javascript? assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void. // 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>(); Local<Object> req_wrap_obj = args[0].As<Object>();
String::AsciiValue name(args[1]); 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_, uv_pipe_connect(&req_wrap->req_,
&wrap->handle_, &wrap->handle_,
*name, *name,

5
src/process_wrap.cc

@ -78,7 +78,10 @@ class ProcessWrap : public HandleWrap {
} }
ProcessWrap(Environment* env, Handle<Object> object) 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() { ~ProcessWrap() {

6
src/req_wrap.h

@ -37,8 +37,10 @@ extern QUEUE req_wrap_queue;
template <typename T> template <typename T>
class ReqWrap : public AsyncWrap { class ReqWrap : public AsyncWrap {
public: public:
ReqWrap(Environment* env, v8::Handle<v8::Object> object) ReqWrap(Environment* env,
: AsyncWrap(env, object) { v8::Handle<v8::Object> object,
AsyncWrap::ProviderType provider = AsyncWrap::PROVIDER_REQWRAP)
: AsyncWrap(env, object, AsyncWrap::PROVIDER_REQWRAP) {
if (env->in_domain()) if (env->in_domain())
object->Set(env->domain_string(), env->domain_array()->Get(0)); object->Set(env->domain_string(), env->domain_array()->Get(0));

5
src/signal_wrap.cc

@ -72,7 +72,10 @@ class SignalWrap : public HandleWrap {
} }
SignalWrap(Environment* env, Handle<Object> object) 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_); int r = uv_signal_init(env->event_loop(), &handle_);
assert(r == 0); assert(r == 0);
} }

9
src/stream_wrap.cc

@ -57,8 +57,9 @@ using v8::Value;
StreamWrap::StreamWrap(Environment* env, StreamWrap::StreamWrap(Environment* env,
Local<Object> object, Local<Object> object,
uv_stream_t* stream) uv_stream_t* stream,
: HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(stream)), AsyncWrap::ProviderType provider)
: HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(stream), provider),
stream_(stream), stream_(stream),
default_callbacks_(this), default_callbacks_(this),
callbacks_(&default_callbacks_) { callbacks_(&default_callbacks_) {
@ -528,7 +529,9 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsObject()); assert(args[0]->IsObject());
Local<Object> req_wrap_obj = args[0].As<Object>(); 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); int err = wrap->callbacks()->DoShutdown(req_wrap, AfterShutdown);
req_wrap->Dispatched(); req_wrap->Dispatched();
if (err) if (err)

5
src/stream_wrap.h

@ -37,6 +37,8 @@ typedef class ReqWrap<uv_shutdown_t> ShutdownWrap;
class WriteWrap: public ReqWrap<uv_write_t> { class WriteWrap: public ReqWrap<uv_write_t> {
public: 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) WriteWrap(Environment* env, v8::Local<v8::Object> obj, StreamWrap* wrap)
: ReqWrap<uv_write_t>(env, obj), : ReqWrap<uv_write_t>(env, obj),
wrap_(wrap) { wrap_(wrap) {
@ -150,7 +152,8 @@ class StreamWrap : public HandleWrap {
StreamWrap(Environment* env, StreamWrap(Environment* env,
v8::Local<v8::Object> object, v8::Local<v8::Object> object,
uv_stream_t* stream); uv_stream_t* stream,
AsyncWrap::ProviderType provider);
~StreamWrap() { ~StreamWrap() {
if (callbacks_ != &default_callbacks_) { if (callbacks_ != &default_callbacks_) {

13
src/tcp_wrap.cc

@ -139,7 +139,10 @@ void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
TCPWrap::TCPWrap(Environment* env, Handle<Object> object) 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_); int r = uv_tcp_init(env->event_loop(), &handle_);
assert(r == 0); // How do we proxy this error up to javascript? assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void. // 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); int err = uv_ip4_addr(*ip_address, port, &addr);
if (err == 0) { 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_, err = uv_tcp_connect(&req_wrap->req_,
&wrap->handle_, &wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr), 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); int err = uv_ip6_addr(*ip_address, port, &addr);
if (err == 0) { 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_, err = uv_tcp_connect(&req_wrap->req_,
&wrap->handle_, &wrap->handle_,
reinterpret_cast<const sockaddr*>(&addr), reinterpret_cast<const sockaddr*>(&addr),

5
src/timer_wrap.cc

@ -83,7 +83,10 @@ class TimerWrap : public HandleWrap {
} }
TimerWrap(Environment* env, Handle<Object> object) 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_); int r = uv_timer_init(env->event_loop(), &handle_);
assert(r == 0); assert(r == 0);
} }

4
src/tls_wrap.cc

@ -68,7 +68,9 @@ TLSCallbacks::TLSCallbacks(Environment* env,
StreamWrapCallbacks* old) StreamWrapCallbacks* old)
: SSLWrap<TLSCallbacks>(env, Unwrap<SecureContext>(sc), kind), : SSLWrap<TLSCallbacks>(env, Unwrap<SecureContext>(sc), kind),
StreamWrapCallbacks(old), 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_(Unwrap<SecureContext>(sc)),
sc_handle_(env->isolate(), sc), sc_handle_(env->isolate(), sc),
enc_in_(NULL), enc_in_(NULL),

5
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) 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); uv_tty_init(env->event_loop(), &handle_, fd, readable);
} }

5
src/udp_wrap.cc

@ -73,7 +73,10 @@ inline bool SendWrap::have_callback() const {
UDPWrap::UDPWrap(Environment* env, Handle<Object> object) 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_); int r = uv_udp_init(env->event_loop(), &handle_);
assert(r == 0); // can't fail anyway assert(r == 0); // can't fail anyway
} }

Loading…
Cancel
Save