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

async_hooks initial implementation #11883

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
async_wrap: use more specific providers
Instead of wrapping several providers into PROVIDER_CRYPTO, have them
all be named after their class. Rename other providers to also match
their class names. With the exception of Parser. Which is actually
HTTPParser.

Add PROVIDER_LENGTH to make better checks in WrapperInfo().
  • Loading branch information
trevnorris committed Apr 12, 2017
commit f090fd2c2d8a1ea361ab3d49783ca83f401f72e7
4 changes: 3 additions & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ intptr_t RetainedAsyncInfo::GetSizeInBytes() {

RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
// No class_id should be the provider type of NONE.
CHECK_NE(NODE_ASYNC_ID_OFFSET, class_id);
CHECK_GT(class_id, NODE_ASYNC_ID_OFFSET);
// And make sure the class_id doesn't extend past the last provider.
CHECK_LE(class_id - NODE_ASYNC_ID_OFFSET, AsyncWrap::PROVIDERS_LENGTH);
CHECK(wrapper->IsObject());
CHECK(!wrapper.IsEmpty());

Expand Down
11 changes: 7 additions & 4 deletions src/async-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,29 @@ namespace node {

#define NODE_ASYNC_PROVIDER_TYPES(V) \
V(NONE) \
V(CRYPTO) \
V(CONNECTION) \
V(FSEVENTWRAP) \
V(FSREQWRAP) \
V(GETADDRINFOREQWRAP) \
V(GETNAMEINFOREQWRAP) \
V(HTTPPARSER) \
V(JSSTREAM) \
V(PIPEWRAP) \
V(PBKDF2REQUEST) \
V(PIPECONNECTWRAP) \
V(PIPEWRAP) \
V(PROCESSWRAP) \
V(QUERYWRAP) \
V(RANDOMBYTESREQUEST) \
V(SHUTDOWNWRAP) \
V(SIGNALWRAP) \
V(STATWATCHER) \
V(TCPWRAP) \
V(TCPCONNECTWRAP) \
V(TCPWRAP) \
V(TIMERWRAP) \
V(TLSWRAP) \
V(TTYWRAP) \
V(UDPWRAP) \
V(UDPSENDWRAP) \
V(UDPWRAP) \
V(WRITEWRAP) \
V(ZLIB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do callbacks from native addons fit into this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncWrap uses an enum so it can store and more easily access the char* of each provider's name for provider_type(), and a couple other things. There will be a native API for async hooks, but I'm not including that in this PR. After this lands I'll post the native API PR.


Expand All @@ -69,6 +71,7 @@ class AsyncWrap : public BaseObject {
PROVIDER_ ## PROVIDER,
NODE_ASYNC_PROVIDER_TYPES(V)
#undef V
PROVIDERS_LENGTH,
};

AsyncWrap(Environment* env,
Expand Down
4 changes: 2 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5315,7 +5315,7 @@ class PBKDF2Request : public AsyncWrap {
char* salt,
int iter,
int keylen)
: AsyncWrap(env, object, AsyncWrap::PROVIDER_CRYPTO),
: AsyncWrap(env, object, AsyncWrap::PROVIDER_PBKDF2REQUEST),
digest_(digest),
error_(0),
passlen_(passlen),
Expand Down Expand Up @@ -5581,7 +5581,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::PROVIDER_CRYPTO),
: AsyncWrap(env, object, AsyncWrap::PROVIDER_RANDOMBYTESREQUEST),
error_(0),
size_(size),
data_(node::Malloc(size)) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class Connection : public AsyncWrap, public SSLWrap<Connection> {
v8::Local<v8::Object> wrap,
SecureContext* sc,
SSLWrap<Connection>::Kind kind)
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO),
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CONNECTION),
SSLWrap<Connection>(env, sc, kind),
bio_read_(nullptr),
bio_write_(nullptr),
Expand Down