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

Commit

Permalink
Fixes #1726, hack to unref process.stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 27, 2011
1 parent abfcd1f commit 0f8f863
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,31 @@
// Note stdout._type is used for test-module-load-list.js

if (binding.isatty(fd)) {
binding.unref();
var tty = NativeModule.require('tty');
stdout = new tty.WriteStream(fd);
stdout._type = "tty";

// FIXME Hack to have stdout not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
binding.unref();
stdout.on('close', function() {
binding.ref();
});
} else if (binding.isStdoutBlocking()) {
var fs = NativeModule.require('fs');
stdout = new fs.WriteStream(null, {fd: fd});
stdout._type = "fs";
} else {
binding.unref();

var net = NativeModule.require('net');
stdout = new net.Stream(fd);

// FIXME Hack to have stdout not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
binding.unref();
stdout.on('close', function() {
binding.ref();
});

// FIXME Should probably have an option in net.Stream to create a
// stream from an existing fd which is writable only. But for now
// we'll just add this hack and set the `readable` member to false.
Expand Down
12 changes: 12 additions & 0 deletions src/node_stdio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ static Handle<Value> Unref(const Arguments& args) {
}


static Handle<Value> Ref(const Arguments& args) {
HandleScope scope;

assert(unref_called == true);

uv_ref(uv_default_loop());

return Null();
}


static Handle<Value> OpenStdin(const Arguments& args) {
HandleScope scope;

Expand Down Expand Up @@ -337,6 +348,7 @@ void Stdio::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_METHOD(target, "openpty", OpenPTY);

NODE_SET_METHOD(target, "unref", Unref);
NODE_SET_METHOD(target, "ref", Ref);

struct sigaction sa;
memset(&sa, 0, sizeof(sa));
Expand Down

0 comments on commit 0f8f863

Please sign in to comment.