Skip to content

Commit

Permalink
Stop lazy loading domains
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored and piscisaureus committed Nov 8, 2011
1 parent 50c81e1 commit 905b36f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
12 changes: 6 additions & 6 deletions lib/dns.js
Expand Up @@ -22,7 +22,7 @@
var cares = process.binding('cares_wrap'),
net = require('net'),
isIp = net.isIP;

var domains = require('domains');

function errnoException(errorno, syscall) {
// TODO make this more compatible with ErrnoException from src/node.cc
Expand Down Expand Up @@ -131,7 +131,7 @@ exports.lookup = function(domain, family, callback) {

function onanswer(addresses) {
if (process.features.domains) {
require('domains').remove(wrap);
domains.remove(wrap);
}

if (addresses) {
Expand All @@ -152,7 +152,7 @@ exports.lookup = function(domain, family, callback) {
}

if (process.features.domains) {
require('domains').add(wrap);
domains.add(wrap);
}

wrap.oncomplete = onanswer;
Expand All @@ -168,7 +168,7 @@ function resolver(bindingName) {
return function query(name, callback) {
function onanswer(status, result) {
if (process.features.domains) {
require('domains').remove(wrap);
domains.remove(wrap);
}

if (!status) {
Expand All @@ -185,7 +185,7 @@ function resolver(bindingName) {
}

if (process.features.domains) {
require('domains').add(wrap);
domains.add(wrap);
}

callback.immediately = true;
Expand Down Expand Up @@ -235,4 +235,4 @@ exports.NOMEM = 'ENOMEM';
exports.NOTFOUND = 'ENOTFOUND';
exports.NOTIMP = 'ENOTIMP';
exports.SERVFAIL = 'ESERVFAIL';
exports.TIMEOUT = 'ETIMEOUT';
exports.TIMEOUT = 'ETIMEOUT';
1 change: 0 additions & 1 deletion lib/domains.js
Expand Up @@ -179,7 +179,6 @@ exports.remove = function(handle) {
} else {
assert.equal(currentDomain, defaultDomain);
}

}
};

Expand Down
7 changes: 4 additions & 3 deletions lib/fs.js
Expand Up @@ -33,6 +33,7 @@ var fs = exports;
var Stream = require('stream').Stream;
var EventEmitter = require('events').EventEmitter;
var assert = require('assert');
var domains = require('domains');

var kMinPoolSpace = 128;
var kPoolSize = 40 * 1024;
Expand All @@ -53,18 +54,18 @@ function wrapReq(method /* , args */) {
var callback = args[l - 1];
args[l - 1] = function() {
// closeReq
require('domains').remove(req);
domains.remove(req);
callback.call(this, arguments);
};
}

var req = binding[method].apply(binding, args);
if (process.features.domains) require('domains').add(req);
if (process.features.domains) domains.add(req);
return req;
}

function closeReq(req) {
if (process.features.domains) require('domains').remove(req);
if (process.features.domains) domains.remove(req);
}


Expand Down
31 changes: 16 additions & 15 deletions lib/timers.js
Expand Up @@ -22,6 +22,7 @@
var Timer = process.binding('timer_wrap').Timer;
var L = require('_linklist');
var assert = require('assert').ok;
var domains = require('domains');

var debug;
if (process.env.NODE_DEBUG && /timer/.test(process.env.NODE_DEBUG)) {
Expand All @@ -33,7 +34,7 @@ if (process.env.NODE_DEBUG && /timer/.test(process.env.NODE_DEBUG)) {

function closeTimer(t) {
t.close();
require('domains').remove(t);
domains.remove(t);
}


Expand Down Expand Up @@ -69,7 +70,7 @@ function insert(item, msecs) {
// the defaultDomain. When it makes callbacks it iterates through a link list
// of pseudo handles and invokes a callback on each. Each item in that
// list can be associated with a domains.
require('domains').addDefaultDomain(list);
domains.addDefaultDomain(list);

list.start(msecs, 0);

Expand All @@ -81,9 +82,9 @@ function insert(item, msecs) {
if (process.features.domains) {
assert(this == list);
assert(list.domain);
assert(list.domain == require('domains').defaultDomain);
assert(require('domains').getCurrent() ==
require('domains').defaultDomain);
assert(list.domain == domains.defaultDomain);
assert(domains.getCurrent() ==
domains.defaultDomain);
}

debug('timeout callback ' + msecs);
Expand All @@ -110,9 +111,9 @@ function insert(item, msecs) {
process.dispatch(first, "_onTimeout");
assert(this == list);
assert(list.domain);
assert(list.domain == require('domains').defaultDomain);
assert(require('domains').getCurrent() ==
require('domains').defaultDomain);
assert(list.domain == domains.defaultDomain);
assert(domains.getCurrent() ==
domains.defaultDomain);
} else {
first._onTimeout();
}
Expand All @@ -125,9 +126,9 @@ function insert(item, msecs) {

if (process.features.domains) {
assert(list.domain);
assert(list.domain == require('domains').defaultDomain);
assert(require('domains').getCurrent() ==
require('domains').defaultDomain,
assert(list.domain == domains.defaultDomain);
assert(domains.getCurrent() ==
domains.defaultDomain,
"not in defaultDomain when we expected to be");
}

Expand All @@ -143,7 +144,7 @@ function insert(item, msecs) {

var unenroll = exports.unenroll = function(item) {
L.remove(item);
require('domains').remove(item);
domains.remove(item);

var list = lists[item._idleTimeout];
// if empty then stop the watcher
Expand Down Expand Up @@ -192,7 +193,7 @@ function TimerElement(after) {
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
require('domains').add(this);
domains.add(this);
}


Expand All @@ -202,7 +203,7 @@ exports.setTimeout = function(callback, after) {
if (after <= 0) {
// Use the slow case for after == 0
timer = new Timer();
require('domains').add(timer);
domains.add(timer);

timer.ontimeout = callback;

Expand Down Expand Up @@ -255,7 +256,7 @@ exports.clearTimeout = function(timer) {

exports.setInterval = function(callback, repeat) {
var timer = new Timer();
require('domains').add(timer);
domains.add(timer);

var args = Array.prototype.slice.call(arguments, 2);
timer.ontimeout = function() {
Expand Down
10 changes: 7 additions & 3 deletions src/node.js
Expand Up @@ -28,6 +28,7 @@
global = this;

var EventEmitter;
var domains;

function startup() {
EventEmitter = NativeModule.require('events').EventEmitter;
Expand All @@ -52,10 +53,13 @@

startup.resolveArgv0();

domains = NativeModule.require('domains');

// There are various modes that Node can run in. The most common two
// are running from a script and running the REPL - but there are a few
// others like the debugger or running --eval arguments. Here we decide
// which mode we run in.


if (NativeModule.exists('_third_party_main')) {
// To allow people to extend Node in different ways, this hook allows
Expand Down Expand Up @@ -188,7 +192,6 @@
if (l === 0) return;

if (process.features.domains) {
var domains = NativeModule.require('domains');
assert(domains.getCurrent() == domains.defaultDomain);
}

Expand Down Expand Up @@ -544,14 +547,15 @@

// The single entry point for all outside world calls into Javascript.
// (It may not yet be th single entry point yet. v0.6 requires it to be.)
// VERY HOT
function dispatch(obj, method, arg0, arg1, arg2, arg3) {
assert(arguments.length < 7);

var domain;
if (obj.domain) {
domain = obj.domain
} else {
domain = NativeModule.require('domains').defaultDomain;
domain = domains.defaultDomain;
}

domain.enter();
Expand All @@ -570,7 +574,7 @@

domain.exit();

NativeModule.require('domains').pollNewDomains();
domains.pollNewDomains();
}

startup();
Expand Down

0 comments on commit 905b36f

Please sign in to comment.