@@ -132,23 +132,22 @@ function replaceHandle(self, newHandle) {
132132}
133133
134134Socket . prototype . bind = function ( port_ /*, address, callback*/ ) {
135- var self = this ;
136135 let port = port_ ;
137136
138- self . _healthCheck ( ) ;
137+ this . _healthCheck ( ) ;
139138
140139 if ( this . _bindState !== BIND_STATE_UNBOUND )
141140 throw new Error ( 'Socket is already bound' ) ;
142141
143142 this . _bindState = BIND_STATE_BINDING ;
144143
145144 if ( typeof arguments [ arguments . length - 1 ] === 'function' )
146- self . once ( 'listening' , arguments [ arguments . length - 1 ] ) ;
145+ this . once ( 'listening' , arguments [ arguments . length - 1 ] ) ;
147146
148147 if ( port instanceof UDP ) {
149- replaceHandle ( self , port ) ;
150- startListening ( self ) ;
151- return self ;
148+ replaceHandle ( this , port ) ;
149+ startListening ( this ) ;
150+ return this ;
152151 }
153152
154153 var address ;
@@ -164,69 +163,68 @@ Socket.prototype.bind = function(port_ /*, address, callback*/) {
164163 }
165164
166165 // defaulting address for bind to all interfaces
167- if ( ! address && self . _handle . lookup === lookup4 ) {
166+ if ( ! address && this . _handle . lookup === lookup4 ) {
168167 address = '0.0.0.0' ;
169- } else if ( ! address && self . _handle . lookup === lookup6 ) {
168+ } else if ( ! address && this . _handle . lookup === lookup6 ) {
170169 address = '::' ;
171170 }
172171
173172 // resolve address first
174- self . _handle . lookup ( address , function ( err , ip ) {
173+ this . _handle . lookup ( address , ( err , ip ) => {
175174 if ( err ) {
176- self . _bindState = BIND_STATE_UNBOUND ;
177- self . emit ( 'error' , err ) ;
175+ this . _bindState = BIND_STATE_UNBOUND ;
176+ this . emit ( 'error' , err ) ;
178177 return ;
179178 }
180179
181180 if ( ! cluster )
182181 cluster = require ( 'cluster' ) ;
183182
184183 var flags = 0 ;
185- if ( self . _reuseAddr )
184+ if ( this . _reuseAddr )
186185 flags |= UV_UDP_REUSEADDR ;
187186
188187 if ( cluster . isWorker && ! exclusive ) {
189- function onHandle ( err , handle ) {
188+ const onHandle = ( err , handle ) => {
190189 if ( err ) {
191190 var ex = exceptionWithHostPort ( err , 'bind' , ip , port ) ;
192- self . emit ( 'error' , ex ) ;
193- self . _bindState = BIND_STATE_UNBOUND ;
191+ this . emit ( 'error' , ex ) ;
192+ this . _bindState = BIND_STATE_UNBOUND ;
194193 return ;
195194 }
196195
197- if ( ! self . _handle )
196+ if ( ! this . _handle )
198197 // handle has been closed in the mean time.
199198 return handle . close ( ) ;
200199
201- replaceHandle ( self , handle ) ;
202- startListening ( self ) ;
203- }
204- cluster . _getServer ( self , {
200+ replaceHandle ( this , handle ) ;
201+ startListening ( this ) ;
202+ } ;
203+ cluster . _getServer ( this , {
205204 address : ip ,
206205 port : port ,
207- addressType : self . type ,
206+ addressType : this . type ,
208207 fd : - 1 ,
209208 flags : flags
210209 } , onHandle ) ;
211-
212210 } else {
213- if ( ! self . _handle )
211+ if ( ! this . _handle )
214212 return ; // handle has been closed in the mean time
215213
216- const err = self . _handle . bind ( ip , port || 0 , flags ) ;
214+ const err = this . _handle . bind ( ip , port || 0 , flags ) ;
217215 if ( err ) {
218216 var ex = exceptionWithHostPort ( err , 'bind' , ip , port ) ;
219- self . emit ( 'error' , ex ) ;
220- self . _bindState = BIND_STATE_UNBOUND ;
217+ this . emit ( 'error' , ex ) ;
218+ this . _bindState = BIND_STATE_UNBOUND ;
221219 // Todo: close?
222220 return ;
223221 }
224222
225- startListening ( self ) ;
223+ startListening ( this ) ;
226224 }
227225 } ) ;
228226
229- return self ;
227+ return this ;
230228} ;
231229
232230
@@ -312,7 +310,6 @@ Socket.prototype.send = function(buffer,
312310 port ,
313311 address ,
314312 callback ) {
315- const self = this ;
316313 let list ;
317314
318315 if ( address || ( port && typeof port !== 'function' ) ) {
@@ -344,24 +341,26 @@ Socket.prototype.send = function(buffer,
344341 if ( typeof callback !== 'function' )
345342 callback = undefined ;
346343
347- self . _healthCheck ( ) ;
344+ this . _healthCheck ( ) ;
348345
349- if ( self . _bindState === BIND_STATE_UNBOUND )
350- self . bind ( { port : 0 , exclusive : true } , null ) ;
346+ if ( this . _bindState === BIND_STATE_UNBOUND )
347+ this . bind ( { port : 0 , exclusive : true } , null ) ;
351348
352349 if ( list . length === 0 )
353350 list . push ( Buffer . alloc ( 0 ) ) ;
354351
355352 // If the socket hasn't been bound yet, push the outbound packet onto the
356353 // send queue and send after binding is complete.
357- if ( self . _bindState !== BIND_STATE_BOUND ) {
358- enqueue ( self , self . send . bind ( self , list , port , address , callback ) ) ;
354+ if ( this . _bindState !== BIND_STATE_BOUND ) {
355+ enqueue ( this , this . send . bind ( this , list , port , address , callback ) ) ;
359356 return ;
360357 }
361358
362- self . _handle . lookup ( address , function afterDns ( ex , ip ) {
363- doSend ( ex , self , ip , list , address , port , callback ) ;
364- } ) ;
359+ const afterDns = ( ex , ip ) => {
360+ doSend ( ex , this , ip , list , address , port , callback ) ;
361+ } ;
362+
363+ this . _handle . lookup ( address , afterDns ) ;
365364} ;
366365
367366
0 commit comments