Skip to content

Commit caaa59c

Browse files
committed
Wrap uv_pipe_open, implement net.Stream(fd);
Fixes simple/test-child-process-ipc on unix.
1 parent 51f2e84 commit caaa59c

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

lib/net_uv.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,24 @@ function Socket(options) {
7878
stream.Stream.call(this);
7979

8080
if (typeof options == 'number') {
81-
// Legacy interface. Uncomment the following lines after
82-
// libuv backend is stable and API compatibile with legaacy.
83-
// console.error('Deprecated interface net.Socket(fd).');
84-
// console.trace();
81+
// Legacy interface.
8582
// Must support legacy interface. NPM depends on it.
8683
// https://github.com/isaacs/npm/blob/c7824f412f0cb59d6f55cf0bc220253c39e6029f/lib/utils/output.js#L110
87-
// TODO Before we can do this we need a way to open a uv_stream_t by fd.
88-
throw new Error("Not yet implemented")
89-
}
84+
var fd = options;
9085

91-
// private
92-
this._handle = options && options.handle;
93-
initSocketHandle(this);
94-
95-
this.allowHalfOpen = options && options.allowHalfOpen;
86+
// Uncomment the following lines after libuv backend is stable and API
87+
// compatibile with legaacy.
88+
// console.error('Deprecated interface net.Socket(fd).');
89+
// console.trace();
90+
this._handle = createPipe();
91+
this._handle.open(fd);
92+
initSocketHandle(this);
93+
} else {
94+
// private
95+
this._handle = options && options.handle;
96+
initSocketHandle(this);
97+
this.allowHalfOpen = options && options.allowHalfOpen;
98+
}
9699
}
97100
util.inherits(Socket, stream.Stream);
98101

src/pipe_wrap.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void PipeWrap::Initialize(Handle<Object> target) {
7070
NODE_SET_PROTOTYPE_METHOD(t, "bind", Bind);
7171
NODE_SET_PROTOTYPE_METHOD(t, "listen", Listen);
7272
NODE_SET_PROTOTYPE_METHOD(t, "connect", Connect);
73+
NODE_SET_PROTOTYPE_METHOD(t, "open", Open);
7374

7475
pipeConstructor = Persistent<Function>::New(t->GetFunction());
7576

@@ -195,6 +196,19 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
195196
}
196197

197198

199+
Handle<Value> PipeWrap::Open(const Arguments& args) {
200+
HandleScope scope;
201+
202+
UNWRAP
203+
204+
int fd = args[0]->IntegerValue();
205+
206+
uv_pipe_open(&wrap->handle_, fd);
207+
208+
return scope.Close(v8::Null());
209+
}
210+
211+
198212
Handle<Value> PipeWrap::Connect(const Arguments& args) {
199213
HandleScope scope;
200214

src/pipe_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class PipeWrap : StreamWrap {
1818
static v8::Handle<v8::Value> Bind(const v8::Arguments& args);
1919
static v8::Handle<v8::Value> Listen(const v8::Arguments& args);
2020
static v8::Handle<v8::Value> Connect(const v8::Arguments& args);
21+
static v8::Handle<v8::Value> Open(const v8::Arguments& args);
2122

2223
static void OnConnection(uv_stream_t* handle, int status);
2324
static void AfterConnect(uv_connect_t* req, int status);

0 commit comments

Comments
 (0)