Skip to content

Commit

Permalink
Merge pull request #21 from jdwilliams15/master
Browse files Browse the repository at this point in the history
Changed socket error handler to handle 'ECONNREFUSED'. In event of ECONN...
  • Loading branch information
EndangeredMassa committed Jun 22, 2014
2 parents 512cfdb + 725afef commit 5fe4ab4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/portscanner.js
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
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 5fe4ab4

Please sign in to comment.