src: pull OnConnection from pipe_wrap and tcp_wrap · nodejs/node@4663393
11#include "pipe_wrap.h"
2233#include "async-wrap.h"
4+#include "connection_wrap.h"
45#include "env.h"
56#include "env-inl.h"
67#include "handle_wrap.h"
@@ -27,7 +28,6 @@ using v8::Integer;
2728using v8::Local;
2829using v8::Object;
2930using v8::String;
30-using v8::Undefined;
3131using v8::Value;
32323333@@ -51,11 +51,6 @@ static void NewPipeConnectWrap(const FunctionCallbackInfo<Value>& args) {
5151}
5252535354-uv_pipe_t* PipeWrap::UVHandle() {
55-return &handle_;
56-}
57-58-5954Local<Object> PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) {
6055 EscapableHandleScope handle_scope(env->isolate());
6156CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
@@ -125,11 +120,10 @@ PipeWrap::PipeWrap(Environment* env,
125120 Local<Object> object,
126121bool ipc,
127122 AsyncWrap* parent)
128- : StreamWrap(env,
129- object,
130-reinterpret_cast<uv_stream_t*>(&handle_),
131- AsyncWrap::PROVIDER_PIPEWRAP,
132- parent) {
123+ : ConnectionWrap(env,
124+ object,
125+ AsyncWrap::PROVIDER_PIPEWRAP,
126+ parent) {
133127int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
134128CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
135129// Suggestion: uv_pipe_init() returns void.
@@ -167,44 +161,6 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
167161}
168162169163170-// TODO(bnoordhuis) maybe share with TCPWrap?
171-void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
172- PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data);
173-CHECK_EQ(&pipe_wrap->handle_, reinterpret_cast<uv_pipe_t*>(handle));
174-175- Environment* env = pipe_wrap->env();
176- HandleScope handle_scope(env->isolate());
177- Context::Scope context_scope(env->context());
178-179-// We should not be getting this callback if someone as already called
180-// uv_close() on the handle.
181-CHECK_EQ(pipe_wrap->persistent().IsEmpty(), false);
182-183- Local<Value> argv[] = {
184-Integer::New(env->isolate(), status),
185-Undefined(env->isolate())
186- };
187-188-if (status != 0) {
189- pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
190-return;
191- }
192-193-// Instanciate the client javascript object and handle.
194- Local<Object> client_obj = Instantiate(env, pipe_wrap);
195-196-// Unwrap the client javascript object.
197- PipeWrap* wrap;
198-ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
199-uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
200-if (uv_accept(handle, client_handle))
201-return;
202-203-// Successful accept. Call the onconnection callback in JavaScript land.
204- argv[1] = client_obj;
205- pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
206-}
207-208164// TODO(bnoordhuis) Maybe share this with TCPWrap?
209165void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
210166 PipeConnectWrap* req_wrap = static_cast<PipeConnectWrap*>(req->data);