@@ -58,7 +58,7 @@ Client.prototype._connect = function() {
58
58
var self = this ;
59
59
60
60
socket
61
- . on ( 'error' , this . _connectionErrorHandler . bind ( this ) )
61
+ . on ( 'error' , this . _onError . bind ( this ) )
62
62
. on ( 'data' , parser . write . bind ( parser ) )
63
63
. on ( 'end' , this . _onEnd . bind ( this ) )
64
64
. connect ( this . port , this . host ) ;
@@ -238,7 +238,7 @@ Client.prototype._handlePacket = function(packet) {
238
238
return ;
239
239
}
240
240
241
- this . _connectionErrorHandler ( Client . _packetToUserObject ( packet ) ) ;
241
+ this . _onError ( Client . _packetToUserObject ( packet ) ) ;
242
242
return ;
243
243
}
244
244
@@ -270,31 +270,6 @@ Client.prototype._handlePacket = function(packet) {
270
270
this . _dequeue ( ) ;
271
271
} ;
272
272
273
- Client . prototype . _connectionErrorHandler = function ( err ) {
274
- this . destroy ( ) ;
275
-
276
- var task = this . _queue [ 0 ] ;
277
- var delegate = ( task )
278
- ? task . delegate
279
- : null ;
280
-
281
- if ( delegate instanceof Query ) {
282
- delegate . emit ( 'error' , err ) ;
283
- return ;
284
- }
285
-
286
- if ( ! delegate ) {
287
- this . emit ( 'error' , err ) ;
288
- } else {
289
- delegate ( err ) ;
290
- this . _queue . shift ( ) ;
291
- }
292
-
293
- if ( this . _queue . length ) {
294
- this . _connect ( ) ;
295
- }
296
- } ;
297
-
298
273
Client . prototype . _sendAuth = function ( greeting ) {
299
274
var token = auth . token ( this . password , greeting . scrambleBuffer ) ;
300
275
var packetSize = (
@@ -360,6 +335,31 @@ Client.prototype._sendOldAuth = function(greeting) {
360
335
this . write ( packet ) ;
361
336
} ;
362
337
338
+ Client . prototype . _onError = function ( err ) {
339
+ this . destroy ( ) ;
340
+
341
+ var task = this . _queue [ 0 ] ;
342
+ var delegate = ( task )
343
+ ? task . delegate
344
+ : null ;
345
+
346
+ if ( delegate instanceof Query ) {
347
+ delegate . emit ( 'error' , err ) ;
348
+ return ;
349
+ }
350
+
351
+ if ( ! delegate ) {
352
+ this . emit ( 'error' , err ) ;
353
+ } else {
354
+ delegate ( err ) ;
355
+ this . _queue . shift ( ) ;
356
+ }
357
+
358
+ if ( this . _queue . length ) {
359
+ this . _connect ( ) ;
360
+ }
361
+ } ;
362
+
363
363
Client . prototype . _onEnd = function ( ) {
364
364
if ( this . ending ) {
365
365
// @todo destroy()?
0 commit comments