From caaa59c559f4ed8b26ab1438f4104f4e93adb098 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 12 Sep 2011 14:59:51 -0700 Subject: [PATCH] Wrap uv_pipe_open, implement net.Stream(fd); Fixes simple/test-child-process-ipc on unix. --- lib/net_uv.js | 27 +++++++++++++++------------ src/pipe_wrap.cc | 14 ++++++++++++++ src/pipe_wrap.h | 1 + 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/net_uv.js b/lib/net_uv.js index 97470f8259..dddc03fcb0 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -78,21 +78,24 @@ function Socket(options) { stream.Stream.call(this); if (typeof options == 'number') { - // Legacy interface. Uncomment the following lines after - // libuv backend is stable and API compatibile with legaacy. - // console.error('Deprecated interface net.Socket(fd).'); - // console.trace(); + // Legacy interface. // Must support legacy interface. NPM depends on it. // https://github.com/isaacs/npm/blob/c7824f412f0cb59d6f55cf0bc220253c39e6029f/lib/utils/output.js#L110 - // TODO Before we can do this we need a way to open a uv_stream_t by fd. - throw new Error("Not yet implemented") - } + var fd = options; - // private - this._handle = options && options.handle; - initSocketHandle(this); - - this.allowHalfOpen = options && options.allowHalfOpen; + // Uncomment the following lines after libuv backend is stable and API + // compatibile with legaacy. + // console.error('Deprecated interface net.Socket(fd).'); + // console.trace(); + this._handle = createPipe(); + this._handle.open(fd); + initSocketHandle(this); + } else { + // private + this._handle = options && options.handle; + initSocketHandle(this); + this.allowHalfOpen = options && options.allowHalfOpen; + } } util.inherits(Socket, stream.Stream); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 247d715df6..f8a8c84990 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -70,6 +70,7 @@ void PipeWrap::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(t, "bind", Bind); NODE_SET_PROTOTYPE_METHOD(t, "listen", Listen); NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect); + NODE_SET_PROTOTYPE_METHOD(t, "open", Open); pipeConstructor = Persistent::New(t->GetFunction()); @@ -195,6 +196,19 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { } +Handle PipeWrap::Open(const Arguments& args) { + HandleScope scope; + + UNWRAP + + int fd = args[0]->IntegerValue(); + + uv_pipe_open(&wrap->handle_, fd); + + return scope.Close(v8::Null()); +} + + Handle PipeWrap::Connect(const Arguments& args) { HandleScope scope; diff --git a/src/pipe_wrap.h b/src/pipe_wrap.h index 65bec64315..1ec51c71f6 100644 --- a/src/pipe_wrap.h +++ b/src/pipe_wrap.h @@ -18,6 +18,7 @@ class PipeWrap : StreamWrap { static v8::Handle Bind(const v8::Arguments& args); static v8::Handle Listen(const v8::Arguments& args); static v8::Handle Connect(const v8::Arguments& args); + static v8::Handle Open(const v8::Arguments& args); static void OnConnection(uv_stream_t* handle, int status); static void AfterConnect(uv_connect_t* req, int status);