mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-19 04:31:36 +00:00
throw when listen is called twice in a row
This commit is contained in:
parent
5be05f2794
commit
4816796fda
@ -48,6 +48,7 @@ function Server (opts) {
|
|||||||
self._trustProxy = !!opts.trustProxy
|
self._trustProxy = !!opts.trustProxy
|
||||||
if (typeof opts.filter === 'function') self._filter = opts.filter
|
if (typeof opts.filter === 'function') self._filter = opts.filter
|
||||||
|
|
||||||
|
self._listenCalled = false
|
||||||
self.listening = false
|
self.listening = false
|
||||||
self.destroyed = false
|
self.destroyed = false
|
||||||
self.torrents = {}
|
self.torrents = {}
|
||||||
@ -115,14 +116,15 @@ Server.prototype._onError = function (err) {
|
|||||||
Server.prototype.listen = function (/* port, hostname, onlistening */) {
|
Server.prototype.listen = function (/* port, hostname, onlistening */) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
|
if (self._listenCalled || self.listening) throw new Error('server already listening')
|
||||||
|
self._listenCalled = true
|
||||||
|
|
||||||
var lastArg = arguments[arguments.length - 1]
|
var lastArg = arguments[arguments.length - 1]
|
||||||
if (typeof lastArg === 'function') self.once('listening', lastArg)
|
if (typeof lastArg === 'function') self.once('listening', lastArg)
|
||||||
|
|
||||||
var port = toNumber(arguments[0]) || arguments[0] || 0
|
var port = toNumber(arguments[0]) || arguments[0] || 0
|
||||||
var hostname = typeof arguments[1] !== 'function' ? arguments[1] : undefined
|
var hostname = typeof arguments[1] !== 'function' ? arguments[1] : undefined
|
||||||
|
|
||||||
if (self.listening) throw new Error('server already listening')
|
|
||||||
|
|
||||||
debug('listen %o %o', port, hostname)
|
debug('listen %o %o', port, hostname)
|
||||||
|
|
||||||
function isObject (obj) {
|
function isObject (obj) {
|
||||||
|
Loading…
Reference in New Issue
Block a user