Skip to content

Commit 4816796

Browse files
committed
throw when listen is called twice in a row
1 parent 5be05f2 commit 4816796

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function Server (opts) {
4848
self._trustProxy = !!opts.trustProxy
4949
if (typeof opts.filter === 'function') self._filter = opts.filter
5050

51+
self._listenCalled = false
5152
self.listening = false
5253
self.destroyed = false
5354
self.torrents = {}
@@ -115,14 +116,15 @@ Server.prototype._onError = function (err) {
115116
Server.prototype.listen = function (/* port, hostname, onlistening */) {
116117
var self = this
117118

119+
if (self._listenCalled || self.listening) throw new Error('server already listening')
120+
self._listenCalled = true
121+
118122
var lastArg = arguments[arguments.length - 1]
119123
if (typeof lastArg === 'function') self.once('listening', lastArg)
120124

121125
var port = toNumber(arguments[0]) || arguments[0] || 0
122126
var hostname = typeof arguments[1] !== 'function' ? arguments[1] : undefined
123127

124-
if (self.listening) throw new Error('server already listening')
125-
126128
debug('listen %o %o', port, hostname)
127129

128130
function isObject (obj) {

0 commit comments

Comments
 (0)