Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Stop lazy loading domains

  • Loading branch information
ry committed Sep 19, 2011
1 parent 9acb93f commit b8023a75d087bcee519741f9b915b2ec86303deb
Showing with 32 additions and 27 deletions.
  1. +5 −5 lib/dns_uv.js
  2. +0 −1 lib/domains.js
  3. +4 −3 lib/fs.js
  4. +16 −15 lib/timers_uv.js
  5. +7 −3 src/node.js
@@ -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
@@ -136,7 +136,7 @@ exports.lookup = function(domain, family, callback) {

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

if (!status) {
@@ -168,7 +168,7 @@ exports.lookup = function(domain, family, callback) {
}

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

callback.immediately = true;
@@ -182,7 +182,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) {
@@ -199,7 +199,7 @@ function resolver(bindingName) {
}

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

callback.immediately = true;
@@ -179,7 +179,6 @@ exports.remove = function(handle) {
} else {
assert.equal(currentDomain, defaultDomain);
}

}
};

@@ -27,6 +27,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;
@@ -47,18 +48,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);
}


@@ -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)) {
@@ -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);
}


@@ -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);

@@ -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);
@@ -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();
}
@@ -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");
}

@@ -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
@@ -192,7 +193,7 @@ function TimerElement(after) {
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
require('domains').add(this);
domains.add(this);
}


@@ -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;

@@ -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() {
@@ -28,6 +28,7 @@
global = this;

var EventEmitter;
var domains;

function startup() {

@@ -68,10 +69,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
@@ -198,7 +202,6 @@
if (l === 0) return;

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

@@ -538,14 +541,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();
@@ -564,7 +568,7 @@

domain.exit();

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

startup();

0 comments on commit b8023a7

Please sign in to comment.
You can’t perform that action at this time.