16 using v8::HandleScope;
23 template <
typename WrapType,
typename UVType>
24 ConnectionWrap<WrapType, UVType>::ConnectionWrap(Environment* env,
26 ProviderType provider)
29 reinterpret_cast<uv_stream_t*>(&handle_),
33 template <
typename WrapType,
typename UVType>
34 void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
36 WrapType* wrap_data =
static_cast<WrapType*
>(handle->data);
37 CHECK_NE(wrap_data,
nullptr);
38 CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));
40 Environment* env = wrap_data->env();
41 HandleScope handle_scope(env->isolate());
42 Context::Scope context_scope(env->context());
46 CHECK_EQ(wrap_data->persistent().IsEmpty(),
false);
48 Local<Value> argv[] = {
50 Undefined(env->isolate())
54 env->set_init_trigger_id(wrap_data->get_id());
56 Local<Object> client_obj = WrapType::Instantiate(env, wrap_data);
60 ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
61 uv_stream_t* client_handle =
62 reinterpret_cast<uv_stream_t*
>(&wrap->handle_);
66 if (uv_accept(handle, client_handle))
72 wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
76 template <
typename WrapType,
typename UVType>
77 void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t*
req,
79 ConnectWrap* req_wrap =
static_cast<ConnectWrap*
>(req->data);
80 CHECK_NE(req_wrap,
nullptr);
81 WrapType* wrap =
static_cast<WrapType*
>(req->handle->data);
82 CHECK_EQ(req_wrap->env(), wrap->env());
83 Environment* env = wrap->env();
85 HandleScope handle_scope(env->isolate());
86 Context::Scope context_scope(env->context());
89 CHECK_EQ(req_wrap->persistent().IsEmpty(),
false);
90 CHECK_EQ(wrap->persistent().IsEmpty(),
false);
92 bool readable, writable;
95 readable = writable = 0;
97 readable = uv_is_readable(req->handle) != 0;
98 writable = uv_is_writable(req->handle) != 0;
101 Local<Value> argv[5] = {
109 req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
114 template ConnectionWrap<PipeWrap, uv_pipe_t>::ConnectionWrap(
116 Local<Object>
object,
117 ProviderType provider);
119 template ConnectionWrap<TCPWrap, uv_tcp_t>::ConnectionWrap(
121 Local<Object>
object,
122 ProviderType provider);
124 template void ConnectionWrap<PipeWrap, uv_pipe_t>::OnConnection(
125 uv_stream_t* handle,
int status);
127 template void ConnectionWrap<TCPWrap, uv_tcp_t>::OnConnection(
128 uv_stream_t* handle,
int status);
130 template void ConnectionWrap<PipeWrap, uv_pipe_t>::AfterConnect(
131 uv_connect_t* handle,
int status);
133 template void ConnectionWrap<TCPWrap, uv_tcp_t>::AfterConnect(
134 uv_connect_t* handle,
int status);
MaybeLocal< Object > New(Isolate *isolate, Local< String > string, enum encoding enc)