cares: add AsyncListener support
This commit is contained in:
parent
95c38107c2
commit
fbe7eec1ec
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#define CARES_STATICLIB
|
#define CARES_STATICLIB
|
||||||
#include "ares.h"
|
#include "ares.h"
|
||||||
|
#include "async-wrap.h"
|
||||||
|
#include "async-wrap-inl.h"
|
||||||
#include "env.h"
|
#include "env.h"
|
||||||
#include "env-inl.h"
|
#include "env-inl.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
@ -220,11 +222,10 @@ static Local<Array> HostentToNames(struct hostent* host) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class QueryWrap {
|
class QueryWrap : public AsyncWrap {
|
||||||
public:
|
public:
|
||||||
QueryWrap(Environment* env, Local<Object> req_wrap_obj) : env_(env) {
|
QueryWrap(Environment* env, Local<Object> req_wrap_obj)
|
||||||
HandleScope scope(node_isolate);
|
: AsyncWrap(env, req_wrap_obj) {
|
||||||
persistent().Reset(node_isolate, req_wrap_obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~QueryWrap() {
|
virtual ~QueryWrap() {
|
||||||
@ -243,14 +244,6 @@ class QueryWrap {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Persistent<Object>& persistent() {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Local<Object> object() {
|
|
||||||
return PersistentToLocal(node_isolate, persistent());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void* GetQueryArg() {
|
void* GetQueryArg() {
|
||||||
return static_cast<void*>(this);
|
return static_cast<void*>(this);
|
||||||
@ -289,11 +282,7 @@ class QueryWrap {
|
|||||||
Integer::New(0, env()->isolate()),
|
Integer::New(0, env()->isolate()),
|
||||||
answer
|
answer
|
||||||
};
|
};
|
||||||
MakeCallback(env(),
|
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
|
||||||
object(),
|
|
||||||
env()->oncomplete_string(),
|
|
||||||
ARRAY_SIZE(argv),
|
|
||||||
argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallOnComplete(Local<Value> answer, Local<Value> family) {
|
void CallOnComplete(Local<Value> answer, Local<Value> family) {
|
||||||
@ -304,11 +293,7 @@ class QueryWrap {
|
|||||||
answer,
|
answer,
|
||||||
family
|
family
|
||||||
};
|
};
|
||||||
MakeCallback(env(),
|
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
|
||||||
object(),
|
|
||||||
env()->oncomplete_string(),
|
|
||||||
ARRAY_SIZE(argv),
|
|
||||||
argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseError(int status) {
|
void ParseError(int status) {
|
||||||
@ -350,7 +335,7 @@ class QueryWrap {
|
|||||||
arg = FIXED_ONE_BYTE_STRING(env()->isolate(), "UNKNOWN_ARES_ERROR");
|
arg = FIXED_ONE_BYTE_STRING(env()->isolate(), "UNKNOWN_ARES_ERROR");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MakeCallback(env(), object(), env()->oncomplete_string(), 1, &arg);
|
MakeCallback(env()->oncomplete_string(), 1, &arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subclasses should implement the appropriate Parse method.
|
// Subclasses should implement the appropriate Parse method.
|
||||||
@ -361,14 +346,6 @@ class QueryWrap {
|
|||||||
virtual void Parse(struct hostent* host) {
|
virtual void Parse(struct hostent* host) {
|
||||||
assert(0);
|
assert(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Environment* env() const {
|
|
||||||
return env_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Persistent<Object> object_;
|
|
||||||
Environment* const env_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -911,11 +888,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
|
|||||||
uv_freeaddrinfo(res);
|
uv_freeaddrinfo(res);
|
||||||
|
|
||||||
// Make the callback into JavaScript
|
// Make the callback into JavaScript
|
||||||
MakeCallback(env,
|
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
|
||||||
req_wrap->object(),
|
|
||||||
env->oncomplete_string(),
|
|
||||||
ARRAY_SIZE(argv),
|
|
||||||
argv);
|
|
||||||
|
|
||||||
delete req_wrap;
|
delete req_wrap;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user