Skip to content

Commit

Permalink
Changed socket error handler to handle 'ECONNREFUSED'. In event of EC…
Browse files Browse the repository at this point in the history
…ONNREFUSED the port is available
  • Loading branch information
jdwilliams15 committed Jun 4, 2014
1 parent 512cfdb commit b1dd496
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/portscanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ portscanner.checkPortStatus = function(port, options, callback) {

var host = options.host || '127.0.0.1'
var timeout = options.timeout || 400
var connectionRefused = false;

var socket = new Socket()
, status = null
Expand All @@ -86,12 +87,20 @@ portscanner.checkPortStatus = function(port, options, callback) {
// Assuming the port is not open if an error. May need to refine based on
// exception
socket.on('error', function(exception) {
error = exception
status = 'closed'
if(exception.code !== "ECONNREFUSED") {
error = exception
}
else
connectionRefused = true;
status = 'closed'
})

// Return after the socket has closed
socket.on('close', function() {
socket.on('close', function(exception) {
if(exception && !connectionRefused)
error = exception;
else
error = null;
callback(error, status)
})

Expand Down

0 comments on commit b1dd496

Please sign in to comment.