Browse Source

FIX: signal-unregister bug

We now restore the default signal behavior when all listeners are
removed for a given signal.

Re-enabled test-signal-unregister
v0.7.4-release
Jonas Pfenniger 15 years ago
committed by Ryan Dahl
parent
commit
4274e6b7d0
  1. 51
      src/node.js
  2. 0
      test/simple/test-signal-unregister.js

51
src/node.js

@ -65,21 +65,48 @@ process.compile("(function (exports) {"
// module.require("events");
// Signal Handlers
(function() {
var signalWatchers = {};
addListener = process.addListener,
removeListener = process.removeListener;
function isSignal (event) {
return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
};
// Wrap addListener for the special signal types
process.addListener = function (type, listener) {
var ret = addListener.apply(this, arguments);
if (isSignal(type)) {
if (!signalWatchers.hasOwnProperty(type)) {
var b = process.binding('signal_watcher'),
w = new b.SignalWatcher(process[type]);
w.callback = function () {
process.emit(type);
}
signalWatchers[type] = w;
w.start();
} else if (this.listeners(type).length === 1) {
signalWatchers[event].start();
}
}
return ret;
}
function isSignal (event) {
return event.slice(0, 3) === 'SIG' && process.hasOwnProperty(event);
};
process.removeListener = function (type, listener) {
var ret = removeListener.apply(this, arguments);
if (isSignal(type)) {
process.assert(signalWatchers.hasOwnProperty(type));
process.addListener("newListener", function (event) {
if (isSignal(event) && process.listeners(event).length === 0) {
var b = process.binding('signal_watcher');
var w = new b.SignalWatcher(process[event]);
w.callback = function () {
process.emit(event);
};
w.start();
if (this.listeners(type).length === 0) {
signalWatchers[type].stop();
}
}
return ret;
}
});
})();
// Timers
function addTimerListener (callback) {

0
test/disabled/test-signal-unregister.js → test/simple/test-signal-unregister.js

Loading…
Cancel
Save