src: centralize class wrap/unwrap
While almost all cases were handled by simple WRAP/UNWRAP macros, this extends those to cover all known occurrences.
This commit is contained in:
parent
e0a8e1bf77
commit
756ae2c536
@ -98,7 +98,8 @@ void FSEventWrap::New(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
|
void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(FSEventWrap)
|
FSEventWrap* wrap;
|
||||||
|
UNWRAP(args.This(), FSEventWrap, wrap);
|
||||||
|
|
||||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
if (args.Length() < 1 || !args[0]->IsString()) {
|
||||||
return ThrowTypeError("Bad arguments");
|
return ThrowTypeError("Bad arguments");
|
||||||
@ -171,13 +172,8 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
|
|||||||
void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
|
void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
// Unwrap manually here. The UNWRAP() macro asserts that wrap != NULL.
|
FSEventWrap* wrap;
|
||||||
// That usually indicates an error but not here: double closes are possible
|
UNWRAP_NO_ABORT(args.This(), FSEventWrap, wrap);
|
||||||
// and legal, HandleWrap::Close() deals with them the same way.
|
|
||||||
assert(!args.This().IsEmpty());
|
|
||||||
assert(args.This()->InternalFieldCount() > 0);
|
|
||||||
void* ptr = args.This()->GetAlignedPointerFromInternalField(0);
|
|
||||||
FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr);
|
|
||||||
|
|
||||||
if (wrap == NULL || wrap->initialized_ == false) return;
|
if (wrap == NULL || wrap->initialized_ == false) return;
|
||||||
wrap->initialized_ = false;
|
wrap->initialized_ = false;
|
||||||
|
@ -41,7 +41,8 @@ static Cached<String> close_sym;
|
|||||||
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
|
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP_NO_ABORT(HandleWrap)
|
HandleWrap* wrap;
|
||||||
|
UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap);
|
||||||
|
|
||||||
if (wrap != NULL && wrap->handle__ != NULL) {
|
if (wrap != NULL && wrap->handle__ != NULL) {
|
||||||
uv_ref(wrap->handle__);
|
uv_ref(wrap->handle__);
|
||||||
@ -53,7 +54,8 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
|
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP_NO_ABORT(HandleWrap)
|
HandleWrap* wrap;
|
||||||
|
UNWRAP_NO_ABORT(args.This(), HandleWrap, wrap);
|
||||||
|
|
||||||
if (wrap != NULL && wrap->handle__ != NULL) {
|
if (wrap != NULL && wrap->handle__ != NULL) {
|
||||||
uv_unref(wrap->handle__);
|
uv_unref(wrap->handle__);
|
||||||
@ -65,8 +67,8 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
|
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
HandleWrap *wrap = static_cast<HandleWrap*>(
|
HandleWrap* wrap;
|
||||||
args.This()->GetAlignedPointerFromInternalField(0));
|
UNWRAP(args.This(), HandleWrap, wrap);
|
||||||
|
|
||||||
// guard against uninitialized handle or double close
|
// guard against uninitialized handle or double close
|
||||||
if (wrap == NULL || wrap->handle__ == NULL) return;
|
if (wrap == NULL || wrap->handle__ == NULL) return;
|
||||||
@ -92,9 +94,8 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
|
|||||||
|
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
assert(persistent().IsEmpty());
|
assert(persistent().IsEmpty());
|
||||||
assert(object->InternalFieldCount() > 0);
|
|
||||||
persistent().Reset(node_isolate, object);
|
persistent().Reset(node_isolate, object);
|
||||||
object->SetAlignedPointerInInternalField(0, this);
|
WRAP(object, this);
|
||||||
QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_);
|
QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +49,6 @@ namespace node {
|
|||||||
// js/c++ boundary crossing. At the javascript layer that should all be
|
// js/c++ boundary crossing. At the javascript layer that should all be
|
||||||
// taken care of.
|
// taken care of.
|
||||||
|
|
||||||
#define UNWRAP_NO_ABORT(type) \
|
|
||||||
assert(!args.This().IsEmpty()); \
|
|
||||||
assert(args.This()->InternalFieldCount() > 0); \
|
|
||||||
type* wrap = static_cast<type*>( \
|
|
||||||
args.This()->GetAlignedPointerFromInternalField(0));
|
|
||||||
|
|
||||||
class HandleWrap {
|
class HandleWrap {
|
||||||
public:
|
public:
|
||||||
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
@ -759,7 +759,8 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo<Value>& args) {
|
|||||||
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_get_tlsext_ticket_keys)
|
#if !defined(OPENSSL_NO_TLSEXT) && defined(SSL_CTX_get_tlsext_ticket_keys)
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(SecureContext);
|
SecureContext* wrap;
|
||||||
|
UNWRAP(args.This(), SecureContext, wrap);
|
||||||
|
|
||||||
Local<Object> buff = Buffer::New(48);
|
Local<Object> buff = Buffer::New(48);
|
||||||
if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_,
|
if (SSL_CTX_get_tlsext_ticket_keys(wrap->ctx_,
|
||||||
@ -783,7 +784,8 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
|
|||||||
return ThrowTypeError("Bad argument");
|
return ThrowTypeError("Bad argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
UNWRAP(SecureContext);
|
SecureContext* wrap;
|
||||||
|
UNWRAP(args.This(), SecureContext, wrap);
|
||||||
|
|
||||||
if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_,
|
if (SSL_CTX_set_tlsext_ticket_keys(wrap->ctx_,
|
||||||
Buffer::Data(args[0]),
|
Buffer::Data(args[0]),
|
||||||
|
@ -207,16 +207,36 @@ inline static void ThrowUVException(int errorno,
|
|||||||
|
|
||||||
NO_RETURN void FatalError(const char* location, const char* message);
|
NO_RETURN void FatalError(const char* location, const char* message);
|
||||||
|
|
||||||
#define UNWRAP(type) \
|
#define WRAP(Object, Pointer) \
|
||||||
assert(!args.This().IsEmpty()); \
|
do { \
|
||||||
assert(args.This()->InternalFieldCount() > 0); \
|
assert(!Object.IsEmpty()); \
|
||||||
type* wrap = static_cast<type*>( \
|
assert(Object->InternalFieldCount() > 0); \
|
||||||
args.This()->GetAlignedPointerFromInternalField(0)); \
|
Object->SetAlignedPointerInInternalField(0, Pointer); \
|
||||||
if (!wrap) { \
|
} \
|
||||||
fprintf(stderr, #type ": Aborting due to unwrap failure at %s:%d\n", \
|
while (0)
|
||||||
__FILE__, __LINE__); \
|
|
||||||
abort(); \
|
#define UNWRAP(Object, TypeName, Var) \
|
||||||
}
|
do { \
|
||||||
|
assert(!Object.IsEmpty()); \
|
||||||
|
assert(Object->InternalFieldCount() > 0); \
|
||||||
|
Var = static_cast<TypeName*>( \
|
||||||
|
Object->GetAlignedPointerFromInternalField(0)); \
|
||||||
|
if (!Var) { \
|
||||||
|
fprintf(stderr, #TypeName ": Aborting due to unwrap failure at %s:%d\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
abort(); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
#define UNWRAP_NO_ABORT(Object, TypeName, Var) \
|
||||||
|
do { \
|
||||||
|
assert(!Object.IsEmpty()); \
|
||||||
|
assert(Object->InternalFieldCount() > 0); \
|
||||||
|
Var = static_cast<TypeName*>( \
|
||||||
|
Object->GetAlignedPointerFromInternalField(0)); \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
enum Endianness {
|
enum Endianness {
|
||||||
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
|
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
|
||||||
|
@ -66,9 +66,9 @@ Local<Object> PipeWrap::Instantiate() {
|
|||||||
|
|
||||||
|
|
||||||
PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
|
PipeWrap* PipeWrap::Unwrap(Local<Object> obj) {
|
||||||
assert(!obj.IsEmpty());
|
PipeWrap* wrap;
|
||||||
assert(obj->InternalFieldCount() > 0);
|
UNWRAP(obj, PipeWrap, wrap);
|
||||||
return static_cast<PipeWrap*>(obj->GetAlignedPointerFromInternalField(0));
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,7 +145,8 @@ PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
|
|||||||
void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(PipeWrap)
|
PipeWrap* wrap;
|
||||||
|
UNWRAP(args.This(), PipeWrap, wrap);
|
||||||
|
|
||||||
String::AsciiValue name(args[0]);
|
String::AsciiValue name(args[0]);
|
||||||
int err = uv_pipe_bind(&wrap->handle_, *name);
|
int err = uv_pipe_bind(&wrap->handle_, *name);
|
||||||
@ -157,7 +158,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
|
void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(PipeWrap)
|
PipeWrap* wrap;
|
||||||
|
UNWRAP(args.This(), PipeWrap, wrap);
|
||||||
|
|
||||||
int instances = args[0]->Int32Value();
|
int instances = args[0]->Int32Value();
|
||||||
|
|
||||||
@ -169,7 +171,8 @@ void PipeWrap::SetPendingInstances(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(PipeWrap)
|
PipeWrap* wrap;
|
||||||
|
UNWRAP(args.This(), PipeWrap, wrap);
|
||||||
|
|
||||||
int backlog = args[0]->Int32Value();
|
int backlog = args[0]->Int32Value();
|
||||||
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
|
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
|
||||||
@ -183,12 +186,12 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
|
void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
PipeWrap* wrap = static_cast<PipeWrap*>(handle->data);
|
PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data);
|
||||||
assert(&wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle));
|
assert(&pipe_wrap->handle_ == reinterpret_cast<uv_pipe_t*>(handle));
|
||||||
|
|
||||||
// We should not be getting this callback if someone as already called
|
// We should not be getting this callback if someone as already called
|
||||||
// uv_close() on the handle.
|
// uv_close() on the handle.
|
||||||
assert(wrap->persistent().IsEmpty() == false);
|
assert(pipe_wrap->persistent().IsEmpty() == false);
|
||||||
|
|
||||||
Local<Value> argv[] = {
|
Local<Value> argv[] = {
|
||||||
Integer::New(status, node_isolate),
|
Integer::New(status, node_isolate),
|
||||||
@ -196,7 +199,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
MakeCallback(wrap->object(), "onconnection", ARRAY_SIZE(argv), argv);
|
MakeCallback(pipe_wrap->object(), "onconnection", ARRAY_SIZE(argv), argv);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,19 +207,18 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
|
|||||||
Local<Object> client_obj = NewInstance(pipeConstructor);
|
Local<Object> client_obj = NewInstance(pipeConstructor);
|
||||||
|
|
||||||
// Unwrap the client javascript object.
|
// Unwrap the client javascript object.
|
||||||
assert(client_obj->InternalFieldCount() > 0);
|
PipeWrap* wrap;
|
||||||
PipeWrap* client_wrap =
|
UNWRAP(client_obj, PipeWrap, wrap);
|
||||||
static_cast<PipeWrap*>(client_obj->GetAlignedPointerFromInternalField(0));
|
uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
|
||||||
uv_stream_t* client_handle =
|
if (uv_accept(handle, client_handle))
|
||||||
reinterpret_cast<uv_stream_t*>(&client_wrap->handle_);
|
return;
|
||||||
if (uv_accept(handle, client_handle)) return;
|
|
||||||
|
|
||||||
// Successful accept. Call the onconnection callback in JavaScript land.
|
// Successful accept. Call the onconnection callback in JavaScript land.
|
||||||
argv[1] = client_obj;
|
argv[1] = client_obj;
|
||||||
if (onconnection_sym.IsEmpty()) {
|
if (onconnection_sym.IsEmpty()) {
|
||||||
onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection");
|
onconnection_sym = FIXED_ONE_BYTE_STRING(node_isolate, "onconnection");
|
||||||
}
|
}
|
||||||
MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
|
MakeCallback(pipe_wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bnoordhuis) Maybe share this with TCPWrap?
|
// TODO(bnoordhuis) Maybe share this with TCPWrap?
|
||||||
@ -260,7 +262,8 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
|
|||||||
void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(PipeWrap)
|
PipeWrap* wrap;
|
||||||
|
UNWRAP(args.This(), PipeWrap, wrap);
|
||||||
|
|
||||||
int fd = args[0]->IntegerValue();
|
int fd = args[0]->IntegerValue();
|
||||||
|
|
||||||
@ -271,7 +274,8 @@ void PipeWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
|
void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(PipeWrap)
|
PipeWrap* wrap;
|
||||||
|
UNWRAP(args.This(), PipeWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(args[1]->IsString());
|
assert(args[1]->IsString());
|
||||||
|
@ -128,7 +128,8 @@ class ProcessWrap : public HandleWrap {
|
|||||||
static void Spawn(const FunctionCallbackInfo<Value>& args) {
|
static void Spawn(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(ProcessWrap)
|
ProcessWrap* wrap;
|
||||||
|
UNWRAP(args.This(), ProcessWrap, wrap);
|
||||||
|
|
||||||
Local<Object> js_options = args[0]->ToObject();
|
Local<Object> js_options = args[0]->ToObject();
|
||||||
|
|
||||||
@ -256,7 +257,8 @@ class ProcessWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Kill(const FunctionCallbackInfo<Value>& args) {
|
static void Kill(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(ProcessWrap)
|
ProcessWrap* wrap;
|
||||||
|
UNWRAP(args.This(), ProcessWrap, wrap);
|
||||||
|
|
||||||
int signal = args[0]->Int32Value();
|
int signal = args[0]->Int32Value();
|
||||||
int err = uv_process_kill(&wrap->process_, signal);
|
int err = uv_process_kill(&wrap->process_, signal);
|
||||||
|
@ -82,7 +82,8 @@ class SignalWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Start(const FunctionCallbackInfo<Value>& args) {
|
static void Start(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(SignalWrap)
|
SignalWrap* wrap;
|
||||||
|
UNWRAP(args.This(), SignalWrap, wrap);
|
||||||
|
|
||||||
int signum = args[0]->Int32Value();
|
int signum = args[0]->Int32Value();
|
||||||
int err = uv_signal_start(&wrap->handle_, OnSignal, signum);
|
int err = uv_signal_start(&wrap->handle_, OnSignal, signum);
|
||||||
@ -91,7 +92,8 @@ class SignalWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Stop(const FunctionCallbackInfo<Value>& args) {
|
static void Stop(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(SignalWrap)
|
SignalWrap* wrap;
|
||||||
|
UNWRAP(args.This(), SignalWrap, wrap);
|
||||||
|
|
||||||
int err = uv_signal_stop(&wrap->handle_);
|
int err = uv_signal_stop(&wrap->handle_);
|
||||||
args.GetReturnValue().Set(err);
|
args.GetReturnValue().Set(err);
|
||||||
|
@ -80,7 +80,8 @@ StreamWrap::StreamWrap(Handle<Object> object, uv_stream_t* stream)
|
|||||||
void StreamWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
|
void StreamWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP_NO_ABORT(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP_NO_ABORT(args.This(), StreamWrap, wrap);
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
if (wrap != NULL && wrap->stream() != NULL) {
|
if (wrap != NULL && wrap->stream() != NULL) {
|
||||||
fd = wrap->stream()->io_watcher.fd;
|
fd = wrap->stream()->io_watcher.fd;
|
||||||
@ -101,7 +102,8 @@ void StreamWrap::UpdateWriteQueueSize() {
|
|||||||
void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
|
void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
if (wrap->is_named_pipe_ipc()) {
|
if (wrap->is_named_pipe_ipc()) {
|
||||||
@ -117,7 +119,8 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void StreamWrap::ReadStop(const FunctionCallbackInfo<Value>& args) {
|
void StreamWrap::ReadStop(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
int err = uv_read_stop(wrap->stream());
|
int err = uv_read_stop(wrap->stream());
|
||||||
args.GetReturnValue().Set(err);
|
args.GetReturnValue().Set(err);
|
||||||
@ -135,15 +138,14 @@ template <class WrapType, class UVType>
|
|||||||
static Local<Object> AcceptHandle(uv_stream_t* pipe) {
|
static Local<Object> AcceptHandle(uv_stream_t* pipe) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
Local<Object> wrap_obj;
|
Local<Object> wrap_obj;
|
||||||
WrapType* wrap;
|
|
||||||
UVType* handle;
|
UVType* handle;
|
||||||
|
|
||||||
wrap_obj = WrapType::Instantiate();
|
wrap_obj = WrapType::Instantiate();
|
||||||
if (wrap_obj.IsEmpty())
|
if (wrap_obj.IsEmpty())
|
||||||
return Local<Object>();
|
return Local<Object>();
|
||||||
|
|
||||||
wrap = static_cast<WrapType*>(
|
WrapType* wrap;
|
||||||
wrap_obj->GetAlignedPointerFromInternalField(0));
|
UNWRAP(wrap_obj, WrapType, wrap);
|
||||||
handle = wrap->UVHandle();
|
handle = wrap->UVHandle();
|
||||||
|
|
||||||
if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle)))
|
if (uv_accept(pipe, reinterpret_cast<uv_stream_t*>(handle)))
|
||||||
@ -202,7 +204,8 @@ size_t StreamWrap::WriteBuffer(Handle<Value> val, uv_buf_t* buf) {
|
|||||||
void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
|
void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(Buffer::HasInstance(args[1]));
|
assert(Buffer::HasInstance(args[1]));
|
||||||
@ -239,7 +242,8 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
|
|||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(args[1]->IsString());
|
assert(args[1]->IsString());
|
||||||
@ -287,11 +291,10 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
|
|||||||
uv_handle_t* send_handle = NULL;
|
uv_handle_t* send_handle = NULL;
|
||||||
|
|
||||||
if (args[2]->IsObject()) {
|
if (args[2]->IsObject()) {
|
||||||
Local<Object> send_handle_obj = args[2]->ToObject();
|
Local<Object> send_handle_obj = args[2].As<Object>();
|
||||||
assert(send_handle_obj->InternalFieldCount() > 0);
|
HandleWrap* wrap;
|
||||||
HandleWrap* send_handle_wrap = static_cast<HandleWrap*>(
|
UNWRAP(send_handle_obj, HandleWrap, wrap);
|
||||||
send_handle_obj->GetAlignedPointerFromInternalField(0));
|
send_handle = wrap->GetHandle();
|
||||||
send_handle = send_handle_wrap->GetHandle();
|
|
||||||
|
|
||||||
// Reference StreamWrap instance to prevent it from being garbage
|
// Reference StreamWrap instance to prevent it from being garbage
|
||||||
// collected before `AfterWrite` is called.
|
// collected before `AfterWrite` is called.
|
||||||
@ -325,7 +328,8 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
|
void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(args[1]->IsArray());
|
assert(args[1]->IsArray());
|
||||||
@ -469,7 +473,8 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
|
|||||||
void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
|
void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(StreamWrap)
|
StreamWrap* wrap;
|
||||||
|
UNWRAP(args.This(), StreamWrap, wrap);
|
||||||
|
|
||||||
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>();
|
||||||
|
@ -129,9 +129,9 @@ void TCPWrap::Initialize(Handle<Object> target) {
|
|||||||
|
|
||||||
|
|
||||||
TCPWrap* TCPWrap::Unwrap(Local<Object> obj) {
|
TCPWrap* TCPWrap::Unwrap(Local<Object> obj) {
|
||||||
assert(!obj.IsEmpty());
|
TCPWrap* wrap;
|
||||||
assert(obj->InternalFieldCount() > 0);
|
UNWRAP(obj, TCPWrap, wrap);
|
||||||
return static_cast<TCPWrap*>(obj->GetAlignedPointerFromInternalField(0));
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,7 +169,8 @@ void TCPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
|
|||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
struct sockaddr_storage address;
|
struct sockaddr_storage address;
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
Local<Object> out = args[0].As<Object>();
|
Local<Object> out = args[0].As<Object>();
|
||||||
@ -191,7 +192,8 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
|
|||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
struct sockaddr_storage address;
|
struct sockaddr_storage address;
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
Local<Object> out = args[0].As<Object>();
|
Local<Object> out = args[0].As<Object>();
|
||||||
@ -212,7 +214,8 @@ void TCPWrap::GetPeerName(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
int enable = static_cast<int>(args[0]->BooleanValue());
|
int enable = static_cast<int>(args[0]->BooleanValue());
|
||||||
int err = uv_tcp_nodelay(&wrap->handle_, enable);
|
int err = uv_tcp_nodelay(&wrap->handle_, enable);
|
||||||
@ -223,7 +226,8 @@ void TCPWrap::SetNoDelay(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
int enable = args[0]->Int32Value();
|
int enable = args[0]->Int32Value();
|
||||||
unsigned int delay = args[1]->Uint32Value();
|
unsigned int delay = args[1]->Uint32Value();
|
||||||
@ -237,7 +241,8 @@ void TCPWrap::SetKeepAlive(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
bool enable = args[0]->BooleanValue();
|
bool enable = args[0]->BooleanValue();
|
||||||
int err = uv_tcp_simultaneous_accepts(&wrap->handle_, enable);
|
int err = uv_tcp_simultaneous_accepts(&wrap->handle_, enable);
|
||||||
@ -248,7 +253,8 @@ void TCPWrap::SetSimultaneousAccepts(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
int fd = args[0]->IntegerValue();
|
int fd = args[0]->IntegerValue();
|
||||||
uv_tcp_open(&wrap->handle_, fd);
|
uv_tcp_open(&wrap->handle_, fd);
|
||||||
}
|
}
|
||||||
@ -257,7 +263,8 @@ void TCPWrap::Open(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
String::AsciiValue ip_address(args[0]);
|
String::AsciiValue ip_address(args[0]);
|
||||||
int port = args[1]->Int32Value();
|
int port = args[1]->Int32Value();
|
||||||
@ -272,7 +279,8 @@ void TCPWrap::Bind(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
String::AsciiValue ip6_address(args[0]);
|
String::AsciiValue ip6_address(args[0]);
|
||||||
int port = args[1]->Int32Value();
|
int port = args[1]->Int32Value();
|
||||||
@ -287,7 +295,8 @@ void TCPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
int backlog = args[0]->Int32Value();
|
int backlog = args[0]->Int32Value();
|
||||||
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
|
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&wrap->handle_),
|
||||||
@ -300,12 +309,12 @@ void TCPWrap::Listen(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
|
void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
TCPWrap* wrap = static_cast<TCPWrap*>(handle->data);
|
TCPWrap* tcp_wrap = static_cast<TCPWrap*>(handle->data);
|
||||||
assert(&wrap->handle_ == reinterpret_cast<uv_tcp_t*>(handle));
|
assert(&tcp_wrap->handle_ == reinterpret_cast<uv_tcp_t*>(handle));
|
||||||
|
|
||||||
// We should not be getting this callback if someone as already called
|
// We should not be getting this callback if someone as already called
|
||||||
// uv_close() on the handle.
|
// uv_close() on the handle.
|
||||||
assert(wrap->persistent().IsEmpty() == false);
|
assert(tcp_wrap->persistent().IsEmpty() == false);
|
||||||
|
|
||||||
Local<Value> argv[2] = {
|
Local<Value> argv[2] = {
|
||||||
Integer::New(status, node_isolate),
|
Integer::New(status, node_isolate),
|
||||||
@ -317,19 +326,17 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
|
|||||||
Local<Object> client_obj = Instantiate();
|
Local<Object> client_obj = Instantiate();
|
||||||
|
|
||||||
// Unwrap the client javascript object.
|
// Unwrap the client javascript object.
|
||||||
assert(client_obj->InternalFieldCount() > 0);
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(client_obj, TCPWrap, wrap);
|
||||||
void* client_wrap_v = client_obj->GetAlignedPointerFromInternalField(0);
|
uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
|
||||||
TCPWrap* client_wrap = static_cast<TCPWrap*>(client_wrap_v);
|
if (uv_accept(handle, client_handle))
|
||||||
uv_stream_t* client_handle =
|
return;
|
||||||
reinterpret_cast<uv_stream_t*>(&client_wrap->handle_);
|
|
||||||
if (uv_accept(handle, client_handle)) return;
|
|
||||||
|
|
||||||
// Successful accept. Call the onconnection callback in JavaScript land.
|
// Successful accept. Call the onconnection callback in JavaScript land.
|
||||||
argv[1] = client_obj;
|
argv[1] = client_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
MakeCallback(wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
|
MakeCallback(tcp_wrap->object(), onconnection_sym, ARRAY_SIZE(argv), argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -360,7 +367,8 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
|
|||||||
void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(args[1]->IsString());
|
assert(args[1]->IsString());
|
||||||
@ -391,7 +399,8 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
|
void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TCPWrap)
|
TCPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TCPWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
assert(args[1]->IsString());
|
assert(args[1]->IsString());
|
||||||
|
@ -85,7 +85,8 @@ class TimerWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Start(const FunctionCallbackInfo<Value>& args) {
|
static void Start(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TimerWrap)
|
TimerWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TimerWrap, wrap);
|
||||||
|
|
||||||
int64_t timeout = args[0]->IntegerValue();
|
int64_t timeout = args[0]->IntegerValue();
|
||||||
int64_t repeat = args[1]->IntegerValue();
|
int64_t repeat = args[1]->IntegerValue();
|
||||||
@ -95,7 +96,8 @@ class TimerWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Stop(const FunctionCallbackInfo<Value>& args) {
|
static void Stop(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TimerWrap)
|
TimerWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TimerWrap, wrap);
|
||||||
|
|
||||||
int err = uv_timer_stop(&wrap->handle_);
|
int err = uv_timer_stop(&wrap->handle_);
|
||||||
args.GetReturnValue().Set(err);
|
args.GetReturnValue().Set(err);
|
||||||
@ -103,7 +105,8 @@ class TimerWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void Again(const FunctionCallbackInfo<Value>& args) {
|
static void Again(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TimerWrap)
|
TimerWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TimerWrap, wrap);
|
||||||
|
|
||||||
int err = uv_timer_again(&wrap->handle_);
|
int err = uv_timer_again(&wrap->handle_);
|
||||||
args.GetReturnValue().Set(err);
|
args.GetReturnValue().Set(err);
|
||||||
@ -111,7 +114,8 @@ class TimerWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void SetRepeat(const FunctionCallbackInfo<Value>& args) {
|
static void SetRepeat(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TimerWrap)
|
TimerWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TimerWrap, wrap);
|
||||||
|
|
||||||
int64_t repeat = args[0]->IntegerValue();
|
int64_t repeat = args[0]->IntegerValue();
|
||||||
uv_timer_set_repeat(&wrap->handle_, repeat);
|
uv_timer_set_repeat(&wrap->handle_, repeat);
|
||||||
@ -120,7 +124,8 @@ class TimerWrap : public HandleWrap {
|
|||||||
|
|
||||||
static void GetRepeat(const FunctionCallbackInfo<Value>& args) {
|
static void GetRepeat(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TimerWrap)
|
TimerWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TimerWrap, wrap);
|
||||||
|
|
||||||
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
|
int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
|
||||||
args.GetReturnValue().Set(static_cast<double>(repeat));
|
args.GetReturnValue().Set(static_cast<double>(repeat));
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "node_crypto_clienthello-inl.h"
|
#include "node_crypto_clienthello-inl.h"
|
||||||
#include "node_wrap.h" // WithGenericStream
|
#include "node_wrap.h" // WithGenericStream
|
||||||
#include "node_counters.h"
|
#include "node_counters.h"
|
||||||
|
#include "node_internals.h"
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ TLSCallbacks::TLSCallbacks(Kind kind,
|
|||||||
sc_handle_.Reset(node_isolate, sc);
|
sc_handle_.Reset(node_isolate, sc);
|
||||||
|
|
||||||
Local<Object> object = NewInstance(tlsWrap);
|
Local<Object> object = NewInstance(tlsWrap);
|
||||||
object->SetAlignedPointerInInternalField(0, this);
|
WRAP(object, this);
|
||||||
persistent().Reset(node_isolate, object);
|
persistent().Reset(node_isolate, object);
|
||||||
|
|
||||||
// Initialize queue for clearIn writes
|
// Initialize queue for clearIn writes
|
||||||
@ -331,7 +332,8 @@ void TLSCallbacks::Wrap(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::Start(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::Start(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (wrap->started_)
|
if (wrap->started_)
|
||||||
return ThrowError("Already started.");
|
return ThrowError("Already started.");
|
||||||
@ -666,7 +668,8 @@ int TLSCallbacks::DoShutdown(ShutdownWrap* req_wrap, uv_shutdown_cb cb) {
|
|||||||
void TLSCallbacks::VerifyError(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::VerifyError(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
// XXX Do this check in JS land?
|
// XXX Do this check in JS land?
|
||||||
X509* peer_cert = SSL_get_peer_certificate(wrap->ssl_);
|
X509* peer_cert = SSL_get_peer_certificate(wrap->ssl_);
|
||||||
@ -732,7 +735,8 @@ void TLSCallbacks::VerifyError(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::SetVerifyMode(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::SetVerifyMode(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (args.Length() < 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
|
if (args.Length() < 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean())
|
||||||
return ThrowTypeError("Bad arguments, expected two booleans");
|
return ThrowTypeError("Bad arguments, expected two booleans");
|
||||||
@ -760,7 +764,8 @@ void TLSCallbacks::SetVerifyMode(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
void TLSCallbacks::IsSessionReused(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::IsSessionReused(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
bool yes = SSL_session_reused(wrap->ssl_);
|
bool yes = SSL_session_reused(wrap->ssl_);
|
||||||
args.GetReturnValue().Set(yes);
|
args.GetReturnValue().Set(yes);
|
||||||
}
|
}
|
||||||
@ -770,18 +775,19 @@ void TLSCallbacks::EnableSessionCallbacks(
|
|||||||
const FunctionCallbackInfo<Value>& args) {
|
const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
wrap->session_callbacks_ = true;
|
wrap->session_callbacks_ = true;
|
||||||
EnableHelloParser(args);
|
EnableHelloParser(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TLSCallbacks::EnableHelloParser(
|
void TLSCallbacks::EnableHelloParser(const FunctionCallbackInfo<Value>& args) {
|
||||||
const FunctionCallbackInfo<Value>& args) {
|
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
wrap->hello_.Start(OnClientHello, OnClientHelloParseEnd, wrap);
|
wrap->hello_.Start(OnClientHello, OnClientHelloParseEnd, wrap);
|
||||||
}
|
}
|
||||||
@ -822,7 +828,8 @@ void TLSCallbacks::OnClientHelloParseEnd(void* arg) {
|
|||||||
void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
Local<Object> info = Object::New();
|
Local<Object> info = Object::New();
|
||||||
X509* peer_cert = SSL_get_peer_certificate(wrap->ssl_);
|
X509* peer_cert = SSL_get_peer_certificate(wrap->ssl_);
|
||||||
@ -955,7 +962,8 @@ void TLSCallbacks::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::GetSession(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::GetSession(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
SSL_SESSION* sess = SSL_get_session(wrap->ssl_);
|
SSL_SESSION* sess = SSL_get_session(wrap->ssl_);
|
||||||
if (!sess) return;
|
if (!sess) return;
|
||||||
@ -980,7 +988,8 @@ void TLSCallbacks::GetSession(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::SetSession(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::SetSession(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (wrap->started_)
|
if (wrap->started_)
|
||||||
return ThrowError("Already started.");
|
return ThrowError("Already started.");
|
||||||
@ -1015,7 +1024,8 @@ void TLSCallbacks::SetSession(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::LoadSession(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::LoadSession(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (args.Length() >= 1 && Buffer::HasInstance(args[0])) {
|
if (args.Length() >= 1 && Buffer::HasInstance(args[0])) {
|
||||||
ssize_t slen = Buffer::Length(args[0]);
|
ssize_t slen = Buffer::Length(args[0]);
|
||||||
@ -1045,7 +1055,8 @@ void TLSCallbacks::LoadSession(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::EndParser(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::EndParser(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
wrap->hello_.End();
|
wrap->hello_.End();
|
||||||
}
|
}
|
||||||
@ -1054,7 +1065,8 @@ void TLSCallbacks::EndParser(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
const SSL_CIPHER* c;
|
const SSL_CIPHER* c;
|
||||||
|
|
||||||
@ -1147,7 +1159,8 @@ int TLSCallbacks::SelectNextProtoCallback(SSL* s,
|
|||||||
void TLSCallbacks::GetNegotiatedProto(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::GetNegotiatedProto(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (wrap->kind_ == kTLSClient) {
|
if (wrap->kind_ == kTLSClient) {
|
||||||
if (wrap->selected_npn_proto_.IsEmpty() == false) {
|
if (wrap->selected_npn_proto_.IsEmpty() == false) {
|
||||||
@ -1173,7 +1186,8 @@ void TLSCallbacks::GetNegotiatedProto(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (args.Length() < 1 || !Buffer::HasInstance(args[0]))
|
if (args.Length() < 1 || !Buffer::HasInstance(args[0]))
|
||||||
return ThrowTypeError("Must give a Buffer as first argument");
|
return ThrowTypeError("Must give a Buffer as first argument");
|
||||||
@ -1187,7 +1201,8 @@ void TLSCallbacks::SetNPNProtocols(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
const char* servername = SSL_get_servername(wrap->ssl_,
|
const char* servername = SSL_get_servername(wrap->ssl_,
|
||||||
TLSEXT_NAMETYPE_host_name);
|
TLSEXT_NAMETYPE_host_name);
|
||||||
@ -1202,7 +1217,8 @@ void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TLSCallbacks::SetServername(const FunctionCallbackInfo<Value>& args) {
|
void TLSCallbacks::SetServername(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TLSCallbacks);
|
TLSCallbacks* wrap;
|
||||||
|
UNWRAP(args.This(), TLSCallbacks, wrap);
|
||||||
|
|
||||||
if (args.Length() < 1 || !args[0]->IsString())
|
if (args.Length() < 1 || !args[0]->IsString())
|
||||||
return ThrowTypeError("First argument should be a string");
|
return ThrowTypeError("First argument should be a string");
|
||||||
|
@ -87,9 +87,9 @@ void TTYWrap::Initialize(Handle<Object> target) {
|
|||||||
|
|
||||||
|
|
||||||
TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
|
TTYWrap* TTYWrap::Unwrap(Local<Object> obj) {
|
||||||
assert(!obj.IsEmpty());
|
TTYWrap* wrap;
|
||||||
assert(obj->InternalFieldCount() > 0);
|
UNWRAP(obj, TTYWrap, wrap);
|
||||||
return static_cast<TTYWrap*>(obj->GetAlignedPointerFromInternalField(0));
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +133,8 @@ void TTYWrap::IsTTY(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
|
void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TTYWrap)
|
TTYWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TTYWrap, wrap);
|
||||||
assert(args[0]->IsArray());
|
assert(args[0]->IsArray());
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
@ -152,7 +153,8 @@ void TTYWrap::GetWindowSize(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) {
|
void TTYWrap::SetRawMode(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
|
|
||||||
UNWRAP(TTYWrap)
|
TTYWrap* wrap;
|
||||||
|
UNWRAP(args.This(), TTYWrap, wrap);
|
||||||
|
|
||||||
int err = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
|
int err = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
|
||||||
args.GetReturnValue().Set(err);
|
args.GetReturnValue().Set(err);
|
||||||
|
@ -135,7 +135,8 @@ void UDPWrap::New(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
|
void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) {
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
int fd = (wrap == NULL) ? -1 : wrap->handle_.io_watcher.fd;
|
int fd = (wrap == NULL) ? -1 : wrap->handle_.io_watcher.fd;
|
||||||
args.GetReturnValue().Set(fd);
|
args.GetReturnValue().Set(fd);
|
||||||
#endif
|
#endif
|
||||||
@ -146,7 +147,8 @@ void UDPWrap::DoBind(const FunctionCallbackInfo<Value>& args, int family) {
|
|||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
// bind(ip, port, flags)
|
// bind(ip, port, flags)
|
||||||
assert(args.Length() == 3);
|
assert(args.Length() == 3);
|
||||||
@ -184,7 +186,8 @@ void UDPWrap::Bind6(const FunctionCallbackInfo<Value>& args) {
|
|||||||
#define X(name, fn) \
|
#define X(name, fn) \
|
||||||
void UDPWrap::name(const FunctionCallbackInfo<Value>& args) { \
|
void UDPWrap::name(const FunctionCallbackInfo<Value>& args) { \
|
||||||
HandleScope scope(node_isolate); \
|
HandleScope scope(node_isolate); \
|
||||||
UNWRAP(UDPWrap) \
|
UDPWrap* wrap; \
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap); \
|
||||||
assert(args.Length() == 1); \
|
assert(args.Length() == 1); \
|
||||||
int flag = args[0]->Int32Value(); \
|
int flag = args[0]->Int32Value(); \
|
||||||
int err = fn(&wrap->handle_, flag); \
|
int err = fn(&wrap->handle_, flag); \
|
||||||
@ -202,7 +205,8 @@ X(SetMulticastLoopback, uv_udp_set_multicast_loop)
|
|||||||
void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
|
void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args,
|
||||||
uv_membership membership) {
|
uv_membership membership) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
assert(args.Length() == 2);
|
assert(args.Length() == 2);
|
||||||
|
|
||||||
@ -236,7 +240,8 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
|
|||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
// send(req, buffer, offset, length, port, address)
|
// send(req, buffer, offset, length, port, address)
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
@ -304,7 +309,8 @@ void UDPWrap::Send6(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
|
void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
|
int err = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
|
||||||
// UV_EALREADY means that the socket is already bound but that's okay
|
// UV_EALREADY means that the socket is already bound but that's okay
|
||||||
@ -315,7 +321,8 @@ void UDPWrap::RecvStart(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
|
void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
int r = uv_udp_recv_stop(&wrap->handle_);
|
int r = uv_udp_recv_stop(&wrap->handle_);
|
||||||
args.GetReturnValue().Set(r);
|
args.GetReturnValue().Set(r);
|
||||||
@ -325,7 +332,8 @@ void UDPWrap::RecvStop(const FunctionCallbackInfo<Value>& args) {
|
|||||||
void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
|
void UDPWrap::GetSockName(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleScope scope(node_isolate);
|
HandleScope scope(node_isolate);
|
||||||
struct sockaddr_storage address;
|
struct sockaddr_storage address;
|
||||||
UNWRAP(UDPWrap)
|
UDPWrap* wrap;
|
||||||
|
UNWRAP(args.This(), UDPWrap, wrap);
|
||||||
|
|
||||||
assert(args[0]->IsObject());
|
assert(args[0]->IsObject());
|
||||||
Local<Object> obj = args[0].As<Object>();
|
Local<Object> obj = args[0].As<Object>();
|
||||||
@ -405,9 +413,9 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
|
|||||||
|
|
||||||
|
|
||||||
UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
|
UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
|
||||||
assert(!obj.IsEmpty());
|
UDPWrap* wrap;
|
||||||
assert(obj->InternalFieldCount() > 0);
|
UNWRAP(obj, UDPWrap, wrap);
|
||||||
return static_cast<UDPWrap*>(obj->GetAlignedPointerFromInternalField(0));
|
return wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user