diff --git a/src/connection_wrap.cc b/src/connection_wrap.cc index e0052a643b8..01d0388d4de 100644 --- a/src/connection_wrap.cc +++ b/src/connection_wrap.cc @@ -45,10 +45,7 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, // uv_close() on the handle. CHECK_EQ(wrap_data->persistent().IsEmpty(), false); - Local argv[] = { - Integer::New(env->isolate(), status), - Undefined(env->isolate()) - }; + Local client_handle; if (status == 0) { // Instantiate the client javascript object and handle. @@ -59,17 +56,20 @@ void ConnectionWrap::OnConnection(uv_stream_t* handle, // Unwrap the client javascript object. WrapType* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj); - uv_stream_t* client_handle = - reinterpret_cast(&wrap->handle_); + uv_stream_t* client = reinterpret_cast(&wrap->handle_); // uv_accept can fail if the new connection has already been closed, in // which case an EAGAIN (resource temporarily unavailable) will be // returned. - if (uv_accept(handle, client_handle)) + if (uv_accept(handle, client)) return; // Successful accept. Call the onconnection callback in JavaScript land. - argv[1] = client_obj; + client_handle = client_obj; + } else { + client_handle = Undefined(env->isolate()); } + + Local argv[] = { Integer::New(env->isolate(), status), client_handle }; wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv); }