Skip to content

Commit

Permalink
[fix] fix bug where a IPC lisenter won't emit close
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen committed Feb 9, 2012
1 parent 1afc293 commit 2103664
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/layers/IPC.js
Expand Up @@ -18,10 +18,15 @@
// setup abstract layer // setup abstract layer
core.ListenerAbstract.apply(this, arguments); core.ListenerAbstract.apply(this, arguments);


var self = this;

// in case the process die, the connection will be severed // in case the process die, the connection will be severed
this.object.on('exit', this.emit.bind(this, 'close')); this.object.on('exit', function () {
if (self.online === true) {
this.emit('close');
}
});


var self = this;
process.nextTick(function () { process.nextTick(function () {
// setup a new connection with the object // setup a new connection with the object
self.emit('listening'); self.emit('listening');
Expand All @@ -35,15 +40,18 @@


// this will be called from core, when lisenter.close is excuted by user // this will be called from core, when lisenter.close is excuted by user
Listener.prototype.close = function () { Listener.prototype.close = function () {

// since we can't relly close anything we will ask remote to not send messages // since we can't relly close anything we will ask remote to not send messages
// to ask the remote without polution the users remote object you can use the // to ask the remote without polution the users remote object you can use the
// request function. This is not as sophisticated as the one users have, // request function. This is not as sophisticated as the one users have,
// so you have to make sure that a close function exist, and that works. // so you have to make sure that a close function exist, and that works.


// get the first and only connection // get the first and only connection
var self = this;
var connect = this.connections[ Object.keys(this.connections)[0] ]; var connect = this.connections[ Object.keys(this.connections)[0] ];
connect.request('close', [], connect.emit.bind(connect, 'close')); connect.request('close', [], function () {
connect.emit('close');
self.emit('close');
});
}; };


// this will be called from core when layer-lisenter object when it emit connection // this will be called from core when layer-lisenter object when it emit connection
Expand Down Expand Up @@ -82,6 +90,13 @@
// setup abstract layer // setup abstract layer
core.RequesterAbstract.apply(this, arguments); core.RequesterAbstract.apply(this, arguments);


// in case the process die, the connection will be severed
this.object.on('exit', function () {
if (self.online === true) {
this.emit('close');
}
});

// just relay message object they do not need to be parsed // just relay message object they do not need to be parsed
this.object.on('message', this.emit.bind(this, 'message')); this.object.on('message', this.emit.bind(this, 'message'));


Expand Down

0 comments on commit 2103664

Please sign in to comment.