Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-12-19 06:10:40 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-12-27 23:17:14 +0300
commit728579c043dd027dc4557c6ce90a92e57518fbfb (patch)
treedad482be0c1566c041af68ac5a446114e73f8039 /lib/server.js
parentd5ba4e0260d21657780c065c71ed3c5648df5944 (diff)
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
Diffstat (limited to 'lib/server.js')
-rw-r--r--lib/server.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/server.js b/lib/server.js
index dd9a529..4b700a2 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -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) {