lib/network.js
function listen(file, perm) {
  var args = [file]
    , perm = perm || 0700
    , server = this;

  this.file = file;
  this.name = path.basename(file);

  if(this.name === file) {
    file = path.join(process.cwd(), file);
  }

  function onListen() {
    try {
      fs.chmodSync(file, perm);
    }catch(e){}
    log.notice('accepting connections at %s', file);
  }
  args.push(onListen);

  // jump through some hoops for stale sockets
  server.on('error', function (e) {
    if(e.code == 'EADDRINUSE') {
      var client = new net.Socket();
      // handle error trying to talk to server
      client.on('error', function(e) {
        // no other server listening
        if(e.code == 'ECONNREFUSED') {
          fs.unlinkSync(file);
          TcpServer.prototype.listen.apply(server, args);
        }
      });
      client.connect({path: file}, function() {
        // exit with original EADDRINUSE
        throw e;
      });
    }
  });
  Server.prototype.listen.apply(server, args);
}
function listen(file, perm) {
  var args = [file]
    , perm = perm || 0700
    , server = this;

  this.file = file;
  this.name = path.basename(file);

  if(this.name === file) {
    file = path.join(process.cwd(), file);
  }

  function onListen() {
    try {
      fs.chmodSync(file, perm);
    }catch(e){}
    log.notice('accepting connections at %s', file);
  }
  args.push(onListen);

  // jump through some hoops for stale sockets
  server.on('error', function (e) {
    if(e.code == 'EADDRINUSE') {
      var client = new net.Socket();
      // handle error trying to talk to server
      client.on('error', function(e) {
        // no other server listening
        if(e.code == 'ECONNREFUSED') {
          fs.unlinkSync(file);
          TcpServer.prototype.listen.apply(server, args);
        }
      });
      client.connect({path: file}, function() {
        // exit with original EADDRINUSE
        throw e;
      });
    }
  });
  Server.prototype.listen.apply(server, args);
}
function listen ( file , perm ) { var args = [ file ] , perm = perm || 0700 , server = this ; this . file = file ; this . name = path . basename ( file ) ; if ( this . name === file ) { file = path . join ( process . cwd ( ) , file ) ; } function onListen ( ) { try { fs . chmodSync ( file , perm ) ; } catch ( e ) { } log . notice ( 'accepting connections at %s' , file ) ; } args . push ( onListen ) ; // jump through some hoops for stale sockets server . on ( 'error' , function ( e ) { if ( e . code == 'EADDRINUSE' ) { var client = new net . Socket ( ) ; // handle error trying to talk to server client . on ( 'error' , function ( e ) { // no other server listening if ( e . code == 'ECONNREFUSED' ) { fs . unlinkSync ( file ) ; TcpServer . prototype . listen . apply ( server , args ) ; } } ) ; client . connect ( { path : file } , function ( ) { // exit with original EADDRINUSE throw e ; } ) ; } } ) ; Server . prototype . listen . apply ( server , args ) ; }
Listen on a UNIX domain socket.
Listen on a UNIX domain socket .