Skip to content

Commit 4a9af3f

Browse files
committed
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>
1 parent c9abb59 commit 4a9af3f

21 files changed

Lines changed: 109 additions & 38 deletions

src/async-wrap-inl.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@
3535

3636
namespace node {
3737

38-
inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
38+
inline AsyncWrap::AsyncWrap(Environment* env,
39+
v8::Handle<v8::Object> object,
40+
ProviderType provider)
3941
: BaseObject(env, object),
40-
async_flags_(NO_OPTIONS) {
42+
async_flags_(NO_OPTIONS),
43+
provider_type_(provider) {
4144
if (!env->has_async_listener())
4245
return;
4346

@@ -56,14 +59,13 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::Handle<v8::Object> object)
5659
inline AsyncWrap::~AsyncWrap() {
5760
}
5861

59-
60-
inline uint32_t AsyncWrap::async_flags() const {
61-
return async_flags_;
62+
inline uint32_t AsyncWrap::provider_type() const {
63+
return provider_type_;
6264
}
6365

6466

6567
inline bool AsyncWrap::has_async_listener() {
66-
return async_flags() & HAS_ASYNC_LISTENER;
68+
return async_flags_ & HAS_ASYNC_LISTENER;
6769
}
6870

6971

src/async-wrap.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,37 @@ class AsyncWrap : public BaseObject {
3535
HAS_ASYNC_LISTENER = 1
3636
};
3737

38-
inline AsyncWrap(Environment* env, v8::Handle<v8::Object> object);
38+
enum ProviderType {
39+
PROVIDER_NONE = 1 << 0,
40+
PROVIDER_CARES = 1 << 1,
41+
PROVIDER_CONNECTWRAP = 1 << 2,
42+
PROVIDER_CRYPTO = 1 << 3,
43+
PROVIDER_FSEVENTWRAP = 1 << 4,
44+
PROVIDER_GETADDRINFOREQWRAP = 1 << 5,
45+
PROVIDER_PIPEWRAP = 1 << 6,
46+
PROVIDER_PROCESSWRAP = 1 << 7,
47+
PROVIDER_REQWRAP = 1 << 8,
48+
PROVIDER_SHUTDOWNWRAP = 1 << 9,
49+
PROVIDER_SIGNALWRAP = 1 << 10,
50+
PROVIDER_STATWATCHER = 1 << 11,
51+
PROVIDER_TCPWRAP = 1 << 12,
52+
PROVIDER_TIMERWRAP = 1 << 13,
53+
PROVIDER_TLSWRAP = 1 << 14,
54+
PROVIDER_TTYWRAP = 1 << 15,
55+
PROVIDER_UDPWRAP = 1 << 16,
56+
PROVIDER_ZLIB = 1 << 17
57+
};
3958

40-
inline ~AsyncWrap();
59+
inline AsyncWrap(Environment* env,
60+
v8::Handle<v8::Object> object,
61+
ProviderType provider);
4162

42-
inline uint32_t async_flags() const;
63+
inline ~AsyncWrap();
4364

4465
inline bool has_async_listener();
4566

67+
inline uint32_t provider_type() const;
68+
4669
// Only call these within a valid HandleScope.
4770
inline v8::Handle<v8::Value> MakeCallback(const v8::Handle<v8::Function> cb,
4871
int argc,
@@ -65,6 +88,7 @@ class AsyncWrap : public BaseObject {
6588
v8::Handle<v8::Value>* argv);
6689

6790
uint32_t async_flags_;
91+
uint32_t provider_type_;
6892
};
6993

7094
} // namespace node

src/cares_wrap.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static Local<Array> HostentToNames(struct hostent* host) {
224224
class QueryWrap : public AsyncWrap {
225225
public:
226226
QueryWrap(Environment* env, Local<Object> req_wrap_obj)
227-
: AsyncWrap(env, req_wrap_obj) {
227+
: AsyncWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_CARES) {
228228
}
229229

230230
virtual ~QueryWrap() {
@@ -997,7 +997,10 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
997997
abort();
998998
}
999999

1000-
GetAddrInfoReqWrap* req_wrap = new GetAddrInfoReqWrap(env, req_wrap_obj);
1000+
GetAddrInfoReqWrap* req_wrap =
1001+
new GetAddrInfoReqWrap(env,
1002+
req_wrap_obj,
1003+
AsyncWrap::PROVIDER_GETADDRINFOREQWRAP);
10011004

10021005
struct addrinfo hints;
10031006
memset(&hints, 0, sizeof(struct addrinfo));

src/fs_event_wrap.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class FSEventWrap: public HandleWrap {
6565

6666

6767
FSEventWrap::FSEventWrap(Environment* env, Handle<Object> object)
68-
: HandleWrap(env, object, reinterpret_cast<uv_handle_t*>(&handle_)) {
68+
: HandleWrap(env,
69+
object,
70+
reinterpret_cast<uv_handle_t*>(&handle_),
71+
AsyncWrap::PROVIDER_FSEVENTWRAP) {
6972
initialized_ = false;
7073
}
7174

src/handle_wrap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
9090

9191
HandleWrap::HandleWrap(Environment* env,
9292
Handle<Object> object,
93-
uv_handle_t* handle)
94-
: AsyncWrap(env, object),
93+
uv_handle_t* handle,
94+
AsyncWrap::ProviderType provider)
95+
: AsyncWrap(env, object, provider),
9596
flags_(0),
9697
handle__(handle) {
9798
handle__->data = this;

src/handle_wrap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class HandleWrap : public AsyncWrap {
6262
protected:
6363
HandleWrap(Environment* env,
6464
v8::Handle<v8::Object> object,
65-
uv_handle_t* handle);
65+
uv_handle_t* handle,
66+
AsyncWrap::ProviderType provider);
6667
virtual ~HandleWrap();
6768

6869
private:

src/node_crypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,7 +3498,7 @@ class PBKDF2Request : public AsyncWrap {
34983498
char* salt,
34993499
ssize_t iter,
35003500
ssize_t keylen)
3501-
: AsyncWrap(env, object),
3501+
: AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
35023502
digest_(digest),
35033503
error_(0),
35043504
passlen_(passlen),
@@ -3760,7 +3760,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) {
37603760
class RandomBytesRequest : public AsyncWrap {
37613761
public:
37623762
RandomBytesRequest(Environment* env, Local<Object> object, size_t size)
3763-
: AsyncWrap(env, object),
3763+
: AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
37643764
error_(0),
37653765
size_(size),
37663766
data_(static_cast<char*>(malloc(size))) {

src/node_crypto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class Connection : public SSLWrap<Connection>, public AsyncWrap {
297297
SecureContext* sc,
298298
SSLWrap<Connection>::Kind kind)
299299
: SSLWrap<Connection>(env, sc, kind),
300-
AsyncWrap(env, wrap),
300+
AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO),
301301
bio_read_(NULL),
302302
bio_write_(NULL),
303303
hello_offset_(0) {
@@ -583,7 +583,7 @@ class Certificate : public AsyncWrap {
583583
static void ExportChallenge(const v8::FunctionCallbackInfo<v8::Value>& args);
584584

585585
Certificate(Environment* env, v8::Local<v8::Object> wrap)
586-
: AsyncWrap(env, wrap) {
586+
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO) {
587587
MakeWeak<Certificate>(this);
588588
}
589589
};

src/node_stat_watcher.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void Delete(uv_handle_t* handle) {
6666

6767

6868
StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
69-
: AsyncWrap(env, wrap),
69+
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
7070
watcher_(new uv_fs_poll_t) {
7171
MakeWeak<StatWatcher>(this);
7272
uv_fs_poll_init(env->event_loop(), watcher_);

src/node_zlib.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ZCtx : public AsyncWrap {
7474
public:
7575

7676
ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode)
77-
: AsyncWrap(env, wrap),
77+
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_ZLIB),
7878
chunk_size_(0),
7979
dictionary_(NULL),
8080
dictionary_len_(0),

0 commit comments

Comments
 (0)