Skip to content

Commit

Permalink
Detect Arrays from original API
Browse files Browse the repository at this point in the history
Now the original API works with both arrays and start/end ports.
Detection on which method to use is based on argument number.
  • Loading branch information
darthneko committed Jan 28, 2015
1 parent ea48def commit 5a714b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/portscan-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var http = require('http')
, portscanner = require('../lib/portscanner.js')

// Check if one of the ports in the list is available
portscanner.findAPortNotInUseInList([4443, 4444, 4447], '127.0.0.1', function(error, port) {
portscanner.findAPortNotInUse([4443, 4444, 4447], '127.0.0.1', function(error, port) {
if (!error) {
console.log('Available port: ' + port);
} else {
Expand Down
10 changes: 5 additions & 5 deletions lib/portscanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ portscanner.findAPortInUse = function(startPort, endPort, host, callback) {
* necessarily the first open port checked. If no
* open port is found, the value is false.
*/
portscanner.findAPortInUseInList = function(portList, host, callback) {
findAPortWithStatusInList('open', portList, host, callback)
portscanner.findAPortInUse = function(portList, host, callback) {
findAPortWithStatus('open', portList, host, callback)
}

/**
Expand Down Expand Up @@ -72,8 +72,8 @@ portscanner.findAPortNotInUse = function(startPort, endPort, host, callback) {
* necessarily the first closed port checked. If no
* closed port is found, the value is false.
*/
portscanner.findAPortNotInUseInList = function(portList, host, callback) {
findAPortWithStatusInList('closed', portList, host, callback)
portscanner.findAPortNotInUse = function(portList, host, callback) {
findAPortWithStatus('closed', portList, host, callback)
}

/**
Expand Down Expand Up @@ -183,7 +183,7 @@ function findAPortWithStatus(status, startPort, endPort, host, callback) {
})
}

function findAPortWithStatusInList(status, portList, host, callback) {
function findAPortWithStatus(status, portList, host, callback) {
var foundPort = false
var portIndex = 0
var port = portList[portIndex]
Expand Down

0 comments on commit 5a714b2

Please sign in to comment.