From 4816796fda877780d5f331114e5602926de97e56 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Tue, 9 Jun 2015 22:32:04 -0700 Subject: [PATCH] throw when listen is called twice in a row --- server.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index d15c0a4..d8ce08b 100644 --- a/server.js +++ b/server.js @@ -48,6 +48,7 @@ function Server (opts) { self._trustProxy = !!opts.trustProxy if (typeof opts.filter === 'function') self._filter = opts.filter + self._listenCalled = false self.listening = false self.destroyed = false self.torrents = {} @@ -115,14 +116,15 @@ Server.prototype._onError = function (err) { Server.prototype.listen = function (/* port, hostname, onlistening */) { var self = this + if (self._listenCalled || self.listening) throw new Error('server already listening') + self._listenCalled = true + var lastArg = arguments[arguments.length - 1] if (typeof lastArg === 'function') self.once('listening', lastArg) var port = toNumber(arguments[0]) || arguments[0] || 0 var hostname = typeof arguments[1] !== 'function' ? arguments[1] : undefined - if (self.listening) throw new Error('server already listening') - debug('listen %o %o', port, hostname) function isObject (obj) {