Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test improvements: use fixtures #540

Merged
merged 8 commits into from Dec 27, 2015

torrent server only call internal `server.close` once

If the user calls `server.close()` on the http server returned by
`torrnet.createServer()` then we should not call it in
`server.destroy()` or node will return an error
  • Loading branch information
feross committed Dec 19, 2015
commit 728579c043dd027dc4557c6ce90a92e57518fbfb
@@ -12,6 +12,7 @@ function Server (torrent, opts) {
var server = http.createServer(opts)

var sockets = []
var closed = false

server.on('connection', function (socket) {
socket.setTimeout(36000000)
@@ -22,11 +23,20 @@ function Server (torrent, opts) {
})
})

var _close = server.close
server.close = function (cb) {
closed = true
_close.call(server, cb)
}

server.destroy = function (cb) {
sockets.forEach(function (socket) {
socket.destroy()
})
server.close(cb)

// Only call `server.close` if user has not called it already
if (closed) process.nextTick(cb)
else server.close(cb)
}

server.on('request', function (req, res) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.