mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-19 04:31:36 +00:00
listen for error on udp socket
This commit is contained in:
parent
3ca0563e84
commit
d1ac7d930e
15
server.js
15
server.js
@ -50,18 +50,22 @@ function Server (opts) {
|
|||||||
if (opts.http !== false) {
|
if (opts.http !== false) {
|
||||||
self._httpServer = http.createServer()
|
self._httpServer = http.createServer()
|
||||||
self._httpServer.on('request', self._onHttpRequest.bind(self))
|
self._httpServer.on('request', self._onHttpRequest.bind(self))
|
||||||
self._httpServer.on('error', function (err) {
|
self._httpServer.on('error', self._onError.bind(self))
|
||||||
self.emit('error', err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to starting a udp server unless the user explicitly says no
|
// default to starting a udp server unless the user explicitly says no
|
||||||
if (opts.udp !== false) {
|
if (opts.udp !== false) {
|
||||||
self._udpServer = dgram.createSocket('udp4')
|
self._udpServer = dgram.createSocket('udp4')
|
||||||
self._udpServer.on('message', self._onUdpRequest.bind(self))
|
self._udpServer.on('message', self._onUdpRequest.bind(self))
|
||||||
|
self._udpServer.on('error', self._onError.bind(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Server.prototype._onError = function (err) {
|
||||||
|
var self = this
|
||||||
|
self.emit('error', err)
|
||||||
|
}
|
||||||
|
|
||||||
Server.prototype.listen = function (port, onlistening) {
|
Server.prototype.listen = function (port, onlistening) {
|
||||||
var self = this
|
var self = this
|
||||||
var tasks = []
|
var tasks = []
|
||||||
@ -114,7 +118,6 @@ Server.prototype._getSwarm = function (binaryInfoHash) {
|
|||||||
peers: {}
|
peers: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return swarm
|
return swarm
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +442,9 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
|
|||||||
|
|
||||||
function send (buf) {
|
function send (buf) {
|
||||||
socket.send(buf, 0, buf.length, rinfo.port, rinfo.address, function () {
|
socket.send(buf, 0, buf.length, rinfo.port, rinfo.address, function () {
|
||||||
try { socket.close() } catch (err) {}
|
try {
|
||||||
|
socket.close()
|
||||||
|
} catch (err) {}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user