Browse Source

Move process.stdout unref hack to handle_wrap.cc

See #1726
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
7e62bc9828
  1. 23
      src/handle_wrap.cc
  2. 2
      src/handle_wrap.h
  3. 12
      src/node.js
  4. 32
      src/node_stdio.cc
  5. 1
      src/pipe_wrap.cc
  6. 1
      src/tty_wrap.cc

23
src/handle_wrap.cc

@ -34,6 +34,23 @@ void HandleWrap::Initialize(Handle<Object> target) {
} }
// This function is used only for process.stdout. It's put here instead of
// in TTYWrap because here we have access to the Close binding.
Handle<Value> HandleWrap::Unref(const Arguments& args) {
HandleScope scope;
UNWRAP
// Calling this function twice should never happen.
assert(wrap->unref == false);
wrap->unref = true;
uv_unref(uv_default_loop());
return v8::Undefined();
}
Handle<Value> HandleWrap::Close(const Arguments& args) { Handle<Value> HandleWrap::Close(const Arguments& args) {
HandleScope scope; HandleScope scope;
@ -42,6 +59,11 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
assert(!wrap->object_.IsEmpty()); assert(!wrap->object_.IsEmpty());
uv_close(wrap->handle__, OnClose); uv_close(wrap->handle__, OnClose);
if (wrap->unref) {
uv_ref(uv_default_loop());
wrap->unref = false;
}
wrap->StateChange(); wrap->StateChange();
return v8::Null(); return v8::Null();
@ -49,6 +71,7 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) { HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
unref = false;
handle__ = h; handle__ = h;
if (h) { if (h) {
h->data = this; h->data = this;

2
src/handle_wrap.h

@ -27,6 +27,7 @@ class HandleWrap {
public: public:
static void Initialize(v8::Handle<v8::Object> target); static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> Close(const v8::Arguments& args); static v8::Handle<v8::Value> Close(const v8::Arguments& args);
static v8::Handle<v8::Value> Unref(const v8::Arguments& args);
protected: protected:
HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle); HandleWrap(v8::Handle<v8::Object> object, uv_handle_t* handle);
@ -42,6 +43,7 @@ class HandleWrap {
// Using double underscore due to handle_ member in tcp_wrap. Probably // Using double underscore due to handle_ member in tcp_wrap. Probably
// tcp_wrap should rename it's member to 'handle'. // tcp_wrap should rename it's member to 'handle'.
uv_handle_t* handle__; uv_handle_t* handle__;
bool unref;
}; };

12
src/node.js

@ -235,12 +235,9 @@
stdout = new tty.WriteStream(fd); stdout = new tty.WriteStream(fd);
stdout._type = "tty"; stdout._type = "tty";
// FIXME Hack to have stdout not keep the event loop alive. // Hack to have stdout not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726 // See https://github.com/joyent/node/issues/1726
binding.unref(); stdout._handle.unref();
stdout.on('close', function() {
binding.ref();
});
break; break;
case 'FILE': case 'FILE':
@ -262,10 +259,7 @@
// FIXME Hack to have stdout not keep the event loop alive. // FIXME Hack to have stdout not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726 // See https://github.com/joyent/node/issues/1726
binding.unref(); stdout._handle.unref();
stdout.on('close', function() {
binding.ref();
});
break; break;
default: default:

32
src/node_stdio.cc

@ -191,35 +191,6 @@ static Handle<Value> WriteError (const Arguments& args) {
} }
// This exists to prevent process.stdout from keeping the event loop alive.
// It is only ever called in src/node.js during the initalization of
// process.stdout and will fail if called more than once. We do not want to
// expose uv_ref and uv_unref to javascript in general.
// This should be removed in the future!
static bool unref_called = false;
static Handle<Value> Unref(const Arguments& args) {
HandleScope scope;
assert(unref_called == false);
uv_unref(uv_default_loop());
unref_called = true;
return Null();
}
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) { static Handle<Value> OpenStdin(const Arguments& args) {
HandleScope scope; HandleScope scope;
@ -347,9 +318,6 @@ void Stdio::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_METHOD(target, "isatty", IsATTY); NODE_SET_METHOD(target, "isatty", IsATTY);
NODE_SET_METHOD(target, "openpty", OpenPTY); NODE_SET_METHOD(target, "openpty", OpenPTY);
NODE_SET_METHOD(target, "unref", Unref);
NODE_SET_METHOD(target, "ref", Ref);
struct sigaction sa; struct sigaction sa;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sa_handler = HandleSIGCONT; sa.sa_handler = HandleSIGCONT;

1
src/pipe_wrap.cc

@ -61,6 +61,7 @@ void PipeWrap::Initialize(Handle<Object> target) {
t->InstanceTemplate()->SetInternalFieldCount(1); t->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close);
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart);
NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);

1
src/tty_wrap.cc

@ -45,6 +45,7 @@ class TTYWrap : StreamWrap {
t->InstanceTemplate()->SetInternalFieldCount(1); t->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close); NODE_SET_PROTOTYPE_METHOD(t, "close", HandleWrap::Close);
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart); NODE_SET_PROTOTYPE_METHOD(t, "readStart", StreamWrap::ReadStart);
NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop); NODE_SET_PROTOTYPE_METHOD(t, "readStop", StreamWrap::ReadStop);

Loading…
Cancel
Save