Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Wrap uv_pipe_open, implement net.Stream(fd);
Browse files Browse the repository at this point in the history
Fixes simple/test-child-process-ipc on unix.
  • Loading branch information
ry committed Sep 12, 2011
1 parent 51f2e84 commit caaa59c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/net_uv.js
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions src/pipe_wrap.cc
Expand Up @@ -70,6 +70,7 @@ void PipeWrap::Initialize(Handle<Object> 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<Function>::New(t->GetFunction());

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


Handle<Value> 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<Value> PipeWrap::Connect(const Arguments& args) {
HandleScope scope;

Expand Down
1 change: 1 addition & 0 deletions src/pipe_wrap.h
Expand Up @@ -18,6 +18,7 @@ class PipeWrap : StreamWrap {
static v8::Handle<v8::Value> Bind(const v8::Arguments& args);
static v8::Handle<v8::Value> Listen(const v8::Arguments& args);
static v8::Handle<v8::Value> Connect(const v8::Arguments& args);
static v8::Handle<v8::Value> Open(const v8::Arguments& args);

static void OnConnection(uv_stream_t* handle, int status);
static void AfterConnect(uv_connect_t* req, int status);
Expand Down

0 comments on commit caaa59c

Please sign in to comment.