Skip to content

Commit

Permalink
Add --use-uv command-line flag to use libuv backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 17, 2011
1 parent 312ed83 commit 710f8e2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/tty_posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


var binding = process.binding('stdio'),
net = require('net'),
net = require('net_legacy'), // FIXME
inherits = require('util').inherits,
spawn = require('child_process').spawn;

Expand Down
17 changes: 17 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ static uv_async_t eio_want_poll_notifier;
static uv_async_t eio_done_poll_notifier;
static uv_idle_t eio_poller;


// XXX use_uv defaults to false on POSIX platforms and to true on Windows
// platforms. This can be set with "--use-uv" command-line flag. We intend
// to remove the legacy backend once the libuv backend is passing all of the
// tests.
#ifdef __POSIX__
static bool use_uv = false;
#else
static bool use_uv = true;
#endif


// Buffer for getpwnam_r(), getgrpam_r() and other misc callers; keep this
// scoped at file-level rather than method-level to avoid excess stack usage.
static char getbuf[PATH_MAX + 1];
Expand Down Expand Up @@ -2082,6 +2094,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {

process->Set(String::NewSymbol("pid"), Integer::New(getpid()));
process->Set(String::NewSymbol("cov"), cov ? True() : False());
process->Set(String::NewSymbol("useUV"), use_uv ? True() : False());

// -e, --eval
if (eval_string) {
Expand Down Expand Up @@ -2225,6 +2238,7 @@ static void PrintHelp() {
" --vars print various compiled-in variables\n"
" --max-stack-size=val set max v8 stack size (bytes)\n"
" --cov code coverage; writes node-cov.json \n"
" --use-uv use the libuv backend\n"
"\n"
"Enviromental variables:\n"
"NODE_PATH ':'-separated list of directories\n"
Expand All @@ -2250,6 +2264,9 @@ static void ParseArgs(int argc, char **argv) {
} else if (!strcmp(arg, "--cov")) {
cov = true;
argv[i] = const_cast<char*>("");
} else if (!strcmp(arg, "--use-uv")) {
use_uv = true;
argv[i] = const_cast<char*>("");
} else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
printf("%s\n", NODE_VERSION);
exit(0);
Expand Down
17 changes: 17 additions & 0 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,19 @@
var Script = process.binding('evals').NodeScript;
var runInThisContext = Script.runInThisContext;

// A special hook to test the new platform layer. Use the command-line
// flag --use-uv to enable the libuv backend instead of the legacy
// backend.
function translateId(id) {
if (id == 'net') {
return process.useUV ? 'net_uv' : 'net_legacy';
} else {
return id;
}
}

function NativeModule(id) {
id = translateId(id);
this.filename = id + '.js';
this.id = id;
this.exports = {};
Expand All @@ -398,6 +410,8 @@
NativeModule._cache = {};

NativeModule.require = function(id) {
id = translateId(id);

if (id == 'native_module') {
return NativeModule;
}
Expand All @@ -420,14 +434,17 @@
};

NativeModule.getCached = function(id) {
id = translateId(id);
return NativeModule._cache[id];
}

NativeModule.exists = function(id) {
id = translateId(id);
return (id in NativeModule._source);
}

NativeModule.getSource = function(id) {
id = translateId(id);
return NativeModule._source[id];
}

Expand Down

0 comments on commit 710f8e2

Please sign in to comment.