@@ -50,18 +50,22 @@ function Server (opts) {
5050 if ( opts . http !== false ) {
5151 self . _httpServer = http . createServer ( )
5252 self . _httpServer . on ( 'request' , self . _onHttpRequest . bind ( self ) )
53- self . _httpServer . on ( 'error' , function ( err ) {
54- self . emit ( 'error' , err )
55- } )
53+ self . _httpServer . on ( 'error' , self . _onError . bind ( self ) )
5654 }
5755
5856 // default to starting a udp server unless the user explicitly says no
5957 if ( opts . udp !== false ) {
6058 self . _udpServer = dgram . createSocket ( 'udp4' )
6159 self . _udpServer . on ( 'message' , self . _onUdpRequest . bind ( self ) )
60+ self . _udpServer . on ( 'error' , self . _onError . bind ( self ) )
6261 }
6362}
6463
64+ Server . prototype . _onError = function ( err ) {
65+ var self = this
66+ self . emit ( 'error' , err )
67+ }
68+
6569Server . prototype . listen = function ( port , onlistening ) {
6670 var self = this
6771 var tasks = [ ]
@@ -114,7 +118,6 @@ Server.prototype._getSwarm = function (binaryInfoHash) {
114118 peers : { }
115119 }
116120 }
117-
118121 return swarm
119122}
120123
@@ -439,7 +442,9 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
439442
440443 function send ( buf ) {
441444 socket . send ( buf , 0 , buf . length , rinfo . port , rinfo . address , function ( ) {
442- try { socket . close ( ) } catch ( err ) { }
445+ try {
446+ socket . close ( )
447+ } catch ( err ) { }
443448 } )
444449 }
445450
0 commit comments