@@ -22,6 +22,13 @@ var Connection = function(config) {
22
22
this . ssl = config . ssl || false ;
23
23
this . _ending = false ;
24
24
this . _mode = TEXT_MODE ;
25
+ this . _emitMessage = false ;
26
+ var self = this ;
27
+ this . on ( 'newListener' , function ( eventName ) {
28
+ if ( eventName == 'message' ) {
29
+ self . _emitMessage = true ;
30
+ }
31
+ } ) ;
25
32
} ;
26
33
27
34
util . inherits ( Connection , EventEmitter ) ;
@@ -80,18 +87,16 @@ Connection.prototype.connect = function(port, host) {
80
87
} ;
81
88
82
89
Connection . prototype . attachListeners = function ( stream ) {
83
- var self = this ;
84
- stream . on ( 'readable' , function ( ) {
85
- var buff = stream . read ( ) ;
86
- if ( ! buff ) return ;
87
- self . setBuffer ( buff ) ;
88
- var msg = self . parseMessage ( ) ;
89
- while ( msg ) {
90
- self . emit ( 'message' , msg ) ;
91
- self . emit ( msg . name , msg ) ;
92
- msg = self . parseMessage ( ) ;
90
+ stream . on ( 'data' , function ( buff ) {
91
+ this . setBuffer ( buff ) ;
92
+ var msg ;
93
+ while ( msg = this . parseMessage ( ) ) {
94
+ if ( this . _emitMessage ) {
95
+ this . emit ( 'message' , msg ) ;
96
+ }
97
+ this . emit ( msg . name , msg ) ;
93
98
}
94
- } ) ;
99
+ } . bind ( this ) ) ;
95
100
} ;
96
101
97
102
Connection . prototype . requestSsl = function ( config ) {
@@ -401,6 +406,7 @@ Connection.prototype.parseMessage = function() {
401
406
case 0x64 : //d
402
407
return this . parsed ( buffer , length ) ;
403
408
}
409
+ return false ;
404
410
} ;
405
411
406
412
Connection . prototype . parseR = function ( buffer , length ) {
0 commit comments