@@ -67,39 +67,32 @@ Client.prototype._onConnect = function(req, res){
67
67
this . request = req ;
68
68
this . response = res ;
69
69
this . connection = req . connection ;
70
-
71
- if ( ! attachConnection ) attachConnection = ! attachConnection && this . connection . eventsAttached === undefined ;
72
- this . connection . eventsAttached = true ;
70
+
71
+ if ( ! attachConnection ) attachConnection = ! attachConnection && this . connection . eventsAttached === undefined ;
72
+ this . connection . eventsAttached = true ;
73
73
74
74
if ( attachConnection ) {
75
- this . connection . addListener ( 'end' , function ( ) {
76
- self . _onClose ( ) ;
77
- self . connection && self . connection . destroy ( )
78
- } ) ;
79
- this . connection . addListener ( 'timeout' , function ( ) {
75
+ function destroyConnection ( ) {
80
76
self . _onClose ( ) ;
81
77
self . connection && self . connection . destroy ( )
82
- } ) ;
83
- this . connection . addListener ( 'error' , function ( ) {
84
- self . _onClose ( ) ;
85
- self . connection && self . connection . destroy ( )
86
- } ) ;
78
+ } ;
79
+ this . connection . addListener ( 'end' , destroyConnection ) ;
80
+ this . connection . addListener ( 'timeout' , destroyConnection ) ;
81
+ this . connection . addListener ( 'error' , destroyConnection ) ;
87
82
}
88
83
89
84
if ( req ) {
90
- req . addListener ( 'error' , function ( err ) {
91
- req . destroy && req . destroy ( ) ;
92
- } ) ;
93
- req . addListener ( 'timeout' , function ( err ) {
85
+ function destroyRequest ( ) {
94
86
req . destroy && req . destroy ( ) ;
95
- } ) ;
87
+ } ;
88
+ req . addListener ( 'error' , destroyRequest ) ;
89
+ req . addListener ( 'timeout' , destroyRequest ) ;
96
90
if ( res ) {
97
- res . addListener ( 'error' , function ( err ) {
98
- res . destroy && res . destroy ( ) ;
99
- } ) ;
100
- res . addListener ( 'timeout' , function ( err ) {
91
+ function destroyResponse ( ) {
101
92
res . destroy && res . destroy ( ) ;
102
- } ) ;
93
+ }
94
+ res . addListener ( 'error' , destroyResponse ) ;
95
+ res . addListener ( 'timeout' , destroyResponse ) ;
103
96
}
104
97
if ( this . _disconnectTimeout ) clearTimeout ( this . _disconnectTimeout ) ;
105
98
}
0 commit comments