From 0aad61e80205baa5e7e4b4bdc81f53f17edc983c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 12 Sep 2011 17:19:09 -0700 Subject: [PATCH] Use net_uv instead of net_legacy for stdio Also temporary hack to prevent process.stdout from keeping event loop alive by calling uv_unref on process.stdout initialization. --- lib/tty_posix.js | 2 +- src/node.js | 4 +++- src/node_stdio.cc | 20 ++++++++++++++++++++ test/simple/test-module-load-list.js | 6 ++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/tty_posix.js b/lib/tty_posix.js index 66afe14..79a6607 100644 --- a/lib/tty_posix.js +++ b/lib/tty_posix.js @@ -21,7 +21,7 @@ var binding = process.binding('stdio'), - net = require('net_legacy'), // FIXME + net = require('net'), inherits = require('util').inherits; diff --git a/src/node.js b/src/node.js index bebacb3..1ebf3e7 100644 --- a/src/node.js +++ b/src/node.js @@ -221,17 +221,19 @@ var binding = process.binding('stdio'), // FIXME Remove conditional when net is supported again on windows. net = (process.platform !== "win32") - ? NativeModule.require('net_legacy') // fixme! + ? NativeModule.require('net') : undefined, fs = NativeModule.require('fs'), tty = NativeModule.require('tty'), fd = binding.stdoutFD; if (binding.isatty(fd)) { + binding.unref(); stdout = new tty.WriteStream(fd); } else if (binding.isStdoutBlocking()) { stdout = new fs.WriteStream(null, {fd: fd}); } else { + binding.unref(); stdout = new net.Stream(fd); // FIXME Should probably have an option in net.Stream to create a // stream from an existing fd which is writable only. But for now diff --git a/src/node_stdio.cc b/src/node_stdio.cc index 8a8c0b2..41a63cd 100644 --- a/src/node_stdio.cc +++ b/src/node_stdio.cc @@ -191,6 +191,24 @@ static Handle 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 Unref(const Arguments& args) { + HandleScope scope; + + assert(unref_called == false); + + uv_unref(uv_default_loop()); + unref_called = true; + + return Null(); +} + + static Handle OpenStdin(const Arguments& args) { HandleScope scope; @@ -318,6 +336,8 @@ void Stdio::Initialize(v8::Handle target) { NODE_SET_METHOD(target, "isatty", IsATTY); NODE_SET_METHOD(target, "openpty", OpenPTY); + NODE_SET_METHOD(target, "unref", Unref); + struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = HandleSIGCONT; diff --git a/test/simple/test-module-load-list.js b/test/simple/test-module-load-list.js index 513bb68..1c3cc07 100644 --- a/test/simple/test-module-load-list.js +++ b/test/simple/test-module-load-list.js @@ -87,15 +87,13 @@ if (!process.features.uv) { // unix libuv backend. expected = expected.concat([ 'NativeModule console', - 'NativeModule net_legacy', + 'NativeModule net_uv', 'NativeModule timers_uv', 'Binding timer_wrap', 'NativeModule _linklist', - 'Binding net', - 'NativeModule freelist', - 'Binding io_watcher', 'NativeModule tty', 'NativeModule tty_posix', + 'Binding pipe_wrap', 'NativeModule readline' ]); } -- 2.7.4