Skip to content

Commit

Permalink
System now emits "data" events instead of "read" events.
Browse files Browse the repository at this point in the history
This follows the normal stream reader model.
  • Loading branch information
Trakkasure committed Jun 27, 2011
1 parent 988a8c7 commit 49b3751
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/index.js
Expand Up @@ -152,7 +152,7 @@ api.prototype.sentence=function(data) {
if (this.channel[channel]) this.channel[channel].emit('trap',e,this.channel[channel]);
} else // no trap. Send general packet.
if (this.channel[channel])
this.channel[channel].read(this.packet);
this.channel[channel].data(this.packet);
} else
if (this.trap) {
var l=data.split(/=/);
Expand Down Expand Up @@ -506,10 +506,10 @@ function Channel(instance) {
this.buffer=[];
} else {
var b=this.buffer;
this.buffer=[];
b.push('.tag='+this.getId());
this.running(true);
this.saveBuffer(true);
this.buffer=[];
b.push('.tag='+this.getId());
this.callback=writeCallback;
this.callback(this); // allow setup before sending command.
this.callback=null;
Expand All @@ -524,24 +524,26 @@ function Channel(instance) {
instance.packet=[];
this.emit('done',p,this);
this.removeAllListeners('done');
this.removeAllListeners('data');
this.removeAllListeners('read');

This comment has been minimized.

Copy link
@Trakkasure

Trakkasure Jun 27, 2011

Author Owner

This will go away soon.

this.running(false);
if (instance.commands.length) {
var c=instance.commands.shift();
if (this.getConnection().debug>0)
util.debug('Channel ('+this.getConnection().getHost()+":"+this.getId()+') buffered commands('+instance.commands.length+1+'): '+JSON.stringify(c));
util.debug('Channel ('+this.getConnection().getHost()+":"+this.getId()+') buffered commands('+(instance.commands.length+1)+'): '+JSON.stringify(c));
cl=instance.closing;
instance.closing=false;
this.write(c[0],c[1]);
instance.closing=cl;
} else
if (instance.closing||instance.closeOnDone) this.close();
},
read: function(data) { // Don't call instance directly. This is called when a full sentence is received (typically a !re line)
data: function(data) { // Don't call instance directly. This is called when a full sentence is received (typically a !re line)
if (this.getConnection().debug>2)
util.debug('Channel read: '+data);
util.debug('Channel data: '+data);
if (this.saveBuffer())
instance.packet.push(data);
this.emit('data',[data],this);

This comment has been minimized.

Copy link
@Trakkasure

Trakkasure Jun 27, 2011

Author Owner

This will go away soon.

this.emit('read',[data],this);
},
close:function(force) { // Close instance channel.
Expand Down

0 comments on commit 49b3751

Please sign in to comment.