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

#411 Pick an available port on "listen EADDRINUSE" or "listen EACCES" #445

Merged
merged 3 commits into from Nov 9, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Pick an available port instead of crashing with "listen EADDRINUSE" o…

…r "listen EACCES" Fixes: #411
  • Loading branch information
Yoann Ciabaud
Yoann Ciabaud committed Sep 27, 2015
commit 8c14314beea9b3dd2c5dc92a095600724850cbb2
@@ -310,10 +310,23 @@ function runDownload (torrentId) {

// Start http server
server = torrent.createServer()
server.listen(argv.port, function () {

function initServer () {
if (torrent.ready) onReady()
else torrent.once('ready', onReady)
})
}

server.listen(argv.port, initServer)

.on('error', function (err) {
// In case the port is unusable
if (err.code === 'EADDRINUSE') {
// Let the OS choose one for us
server.listen(0, initServer)
}
else throw err
})

server.once('connection', function () {
serving = true
})
@@ -366,8 +379,8 @@ function runDownload (torrentId) {

function onSelection (index) {
href = (argv.airplay || argv.chromecast || argv.xbmc)
? 'http://' + networkAddress() + ':' + argv.port + '/' + index
: 'http://localhost:' + argv.port + '/' + index
? 'http://' + networkAddress() + ':' + server.address().port + '/' + index
: 'http://localhost:' + server.address().port + '/' + index

if (playerName) torrent.files[index].select()
if (argv.stdout) torrent.files[index].createReadStream().pipe(process.stdout)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.