Permalink
Browse files

[fix] fix bug where a IPC lisenter won't emit close

  • Loading branch information...
1 parent 1afc293 commit 2103664f6c3b7a8699cc31c754cc511f3c9a8add @AndreasMadsen committed Feb 9, 2012
Showing with 19 additions and 4 deletions.
  1. +19 −4 lib/layers/IPC.js
View
@@ -18,10 +18,15 @@
// setup abstract layer
core.ListenerAbstract.apply(this, arguments);
+ var self = this;
+
// 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 () {
// setup a new connection with the object
self.emit('listening');
@@ -35,15 +40,18 @@
// this will be called from core, when lisenter.close is excuted by user
Listener.prototype.close = function () {
-
// 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
// 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.
// get the first and only connection
+ var self = this;
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
@@ -82,6 +90,13 @@
// setup abstract layer
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
this.object.on('message', this.emit.bind(this, 'message'));

0 comments on commit 2103664

Please sign in to comment.