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

wip

  • Loading branch information...
ry committed Sep 14, 2011
1 parent 66d2fd2 commit a22cb64c54ac2c710521116b42991f52040aff71
Showing with 40 additions and 23 deletions.
  1. +26 −11 lib/domain.js
  2. +10 −5 lib/timers_uv.js
  3. +0 −1 src/node.js
  4. +4 −6 test/simple/test-domains2.js
@@ -24,6 +24,7 @@ var EventEmitter = require('events').EventEmitter;
var util = require('util');

var domainIds = 0;
var allowBadHandleAccess = false;


var debug;
@@ -68,17 +69,28 @@ Domain.prototype.enter = function() {


Domain.prototype.kill = function() {
for (var i = 0; i < this.handles.length; i++) {
debug("kill handle", this.handles[i]);
if (this.handles[i].close) {
this.handles[i].close();
var handle;
console.error("this.handles.length=" + this.handles.length);
while (handle = this.handles.shift()) {
console.error("shift");
debug("kill handle", handle);
debugger;

if (handle._onTimeout || handle.ontimeout) {
// We may be calling domain.remove(handle) on a domain which is not our
// own. This is because the timers sometimes share a handle
// in JavaScript land.
allowBadHandleAccess = true;
clearTimeout(handle);
allowBadHandleAccess = false;

handle._onTimeout = null
handle.ontimeout = null
} else {
this.handles[i].oncomplete = null;
this.handles[i].ontimeout = null;
this.handles[i]._onTimeout = null;
handle.close();
handle.oncomplete = null;
}
}
this.handles = [];
};


@@ -142,21 +154,24 @@ exports.addDefaultDomain = function(handle) {
exports.remove = function(handle) {
if (process.features.domains) {
// TODO do this in O(1)
debug(currentDomain, "remove", handle);

if (handle.domain) {
if (currentDomain != handle.domain) {
if (!allowBadHandleAccess && currentDomain != handle.domain) {
console.error("(node) Attempting to access a handle outside of the " +
"current domain. Thiis is not allowed. handle =", handle);
throw new Error("bad handle access");
// We should not reach here.
process.exit(-10);
}

var i = handle.domain.handles.indexOf(handle);
handle.domain.handles.splice(i, 1);
handle.domain = null;
} else {
assert.equal(currentDomain, defaultDomain);
}

var i = currentDomain.handles.indexOf(handle);
currentDomain.handles.splice(i, 1);
}
};

@@ -188,6 +188,14 @@ exports.active = function(item) {
*/


function TimerElement(after) {
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
require('domain').add(this);
}


exports.setTimeout = function(callback, after) {
var timer, c, args;

@@ -206,11 +214,7 @@ exports.setTimeout = function(callback, after) {

timer.start(0, 0);
} else {
timer = { _idleTimeout: after };
timer._idlePrev = timer;
timer._idleNext = timer;

require('domain').add(timer);
timer = new TimerElement(after);

if (arguments.length <= 2) {
timer._onTimeout = callback;
@@ -243,6 +247,7 @@ exports.clearTimeout = function(timer) {
if (timer instanceof Timer) {
closeTimer(timer); // for after === 0
} else {
debugger;
exports.unenroll(timer);
}
}
@@ -558,7 +558,6 @@
domain.kill();
}

debugger;
domain.exit();

NativeModule.require('domain').pollNewDomains();
@@ -40,7 +40,7 @@ setTimeout(function() {
console.error("timer 3");
timerCallbacks++;
}, 1);
}, 3);
}, 1);

setTimeout(function() {
timerCallbacks++;
@@ -58,21 +58,19 @@ setTimeout(function() {

var t1 = setTimeout(function() {
assert.ok(false, "should not get here");
}, 4);
}, 1);
assert.ok(t1.domain);
assert.equal(t1.domain, d2);
assert.equal(t1.domain.id, require('domain').getCurrent().id);

var t2 = setTimeout(function() {
assert.ok(false, "should not get here");
}, 3);
}, 1);
assert.equal(t2.domain, d2);

debugger;

this.kill();
});
}, 2);
}, 1);


process.on('exit', function() {

0 comments on commit a22cb64

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