Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2016-07-04 20:20:33 +0300
committerAnna Henningsen <anna@addaleax.net>2016-07-25 10:50:51 +0300
commit46633934fed7dfce289298cf16ea0f4161b77bb7 (patch)
treeb0ebe706e4c45deba7e90361c19c6d30b6cac8fd /src/pipe_wrap.cc
parentb3127df59ab23baa68e915d62ea1997adb5669e0 (diff)
src: pull OnConnection from pipe_wrap and tcp_wrap
One of the issues in #4641 concerns OnConnection in pipe_wrap and tcp_wrap which are very similar with some minor difference in how they are coded. This commit extracts OnConnection so both these classes can share the same implementation. PR-URL: https://github.com/nodejs/node/pull/7547 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/pipe_wrap.cc')
-rw-r--r--src/pipe_wrap.cc54
1 files changed, 5 insertions, 49 deletions
diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc
index 286ea30a87c..8baf04ba7ce 100644
--- a/src/pipe_wrap.cc
+++ b/src/pipe_wrap.cc
@@ -1,6 +1,7 @@
#include "pipe_wrap.h"
#include "async-wrap.h"
+#include "connection_wrap.h"
#include "env.h"
#include "env-inl.h"
#include "handle_wrap.h"
@@ -27,7 +28,6 @@ using v8::Integer;
using v8::Local;
using v8::Object;
using v8::String;
-using v8::Undefined;
using v8::Value;
@@ -51,11 +51,6 @@ static void NewPipeConnectWrap(const FunctionCallbackInfo<Value>& args) {
}
-uv_pipe_t* PipeWrap::UVHandle() {
- return &handle_;
-}
-
-
Local<Object> PipeWrap::Instantiate(Environment* env, AsyncWrap* parent) {
EscapableHandleScope handle_scope(env->isolate());
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
@@ -125,11 +120,10 @@ PipeWrap::PipeWrap(Environment* env,
Local<Object> object,
bool ipc,
AsyncWrap* parent)
- : StreamWrap(env,
- object,
- reinterpret_cast<uv_stream_t*>(&handle_),
- AsyncWrap::PROVIDER_PIPEWRAP,
- parent) {
+ : ConnectionWrap(env,
+ object,
+ AsyncWrap::PROVIDER_PIPEWRAP,
+ parent) {
int r = uv_pipe_init(env->event_loop(), &handle_, ipc);
CHECK_EQ(r, 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void.
@@ -167,44 +161,6 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
}
-// TODO(bnoordhuis) maybe share with TCPWrap?
-void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
- PipeWrap* pipe_wrap = static_cast<PipeWrap*>(handle->data);
- CHECK_EQ(&pipe_wrap->handle_, reinterpret_cast<uv_pipe_t*>(handle));
-
- Environment* env = pipe_wrap->env();
- HandleScope handle_scope(env->isolate());
- Context::Scope context_scope(env->context());
-
- // We should not be getting this callback if someone as already called
- // uv_close() on the handle.
- CHECK_EQ(pipe_wrap->persistent().IsEmpty(), false);
-
- Local<Value> argv[] = {
- Integer::New(env->isolate(), status),
- Undefined(env->isolate())
- };
-
- if (status != 0) {
- pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
- return;
- }
-
- // Instanciate the client javascript object and handle.
- Local<Object> client_obj = Instantiate(env, pipe_wrap);
-
- // Unwrap the client javascript object.
- PipeWrap* wrap;
- ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
- uv_stream_t* client_handle = reinterpret_cast<uv_stream_t*>(&wrap->handle_);
- if (uv_accept(handle, client_handle))
- return;
-
- // Successful accept. Call the onconnection callback in JavaScript land.
- argv[1] = client_obj;
- pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
-}
-
// TODO(bnoordhuis) Maybe share this with TCPWrap?
void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
PipeConnectWrap* req_wrap = static_cast<PipeConnectWrap*>(req->data);