lib/server.js
function listen() {
  var args = []
    , port = this.conf.get(ConfigKey.PORT)
    , socket = this.conf.get(ConfigKey.UNIXSOCKET)
    , perm = this.conf.get(ConfigKey.UNIXSOCKETPERM)
    , backlog = this.conf.get(ConfigKey.TCP_BACKLOG)
    , cb = typeof arguments[arguments.length - 1] === 'function'
      ? arguments[arguments.length - 1] : null
    , tcp
    , unix;

  if(socket) {
    unix = this._unix = new UnixServer(this);
  }

  // tcp: server.listen(port, [host], [backlog], [callback])
  // unix socket: server.listen(path, [callback])

  // port zero means don't listen on a tcp port
  if(port !== 0) {
    tcp = this._tcp = new TcpServer(this);

    // port comes first
    args.unshift(port);

    // backlog is penultimate argument
    if(typeof backlog === 'number') {
      args.push(backlog);
    }

    //console.dir(args);

    // cb is last argument
    if(cb) args.push(cb);

    function onListen() {
      // for server info, the actual port or socket in use
      // stored on the state, null if listen was never called
      // or if the bind failed, could also be a unix socket
      var addr = tcp.address();
      var port = addr.port;
      this.state.addr = addr;

      // only write pid if we listen
      if(this._daemonized) {
        daemon.pid.write(this.conf);
      }

      this.emit('listen', port);
      this.log.notice('accepting connections on port %s', port);

      // might be listening on a unix socket too
      if(unix) unix.listen(socket, perm);
    }

    tcp.once('listening', onListen.bind(this));
    tcp.listen.apply(tcp, args);
  // just a unix socket
  }else if(unix) {
    unix.listen(socket, perm);
  }
}
function listen() {
  var args = []
    , port = this.conf.get(ConfigKey.PORT)
    , socket = this.conf.get(ConfigKey.UNIXSOCKET)
    , perm = this.conf.get(ConfigKey.UNIXSOCKETPERM)
    , backlog = this.conf.get(ConfigKey.TCP_BACKLOG)
    , cb = typeof arguments[arguments.length - 1] === 'function'
      ? arguments[arguments.length - 1] : null
    , tcp
    , unix;

  if(socket) {
    unix = this._unix = new UnixServer(this);
  }

  // tcp: server.listen(port, [host], [backlog], [callback])
  // unix socket: server.listen(path, [callback])

  // port zero means don't listen on a tcp port
  if(port !== 0) {
    tcp = this._tcp = new TcpServer(this);

    // port comes first
    args.unshift(port);

    // backlog is penultimate argument
    if(typeof backlog === 'number') {
      args.push(backlog);
    }

    //console.dir(args);

    // cb is last argument
    if(cb) args.push(cb);

    function onListen() {
      // for server info, the actual port or socket in use
      // stored on the state, null if listen was never called
      // or if the bind failed, could also be a unix socket
      var addr = tcp.address();
      var port = addr.port;
      this.state.addr = addr;

      // only write pid if we listen
      if(this._daemonized) {
        daemon.pid.write(this.conf);
      }

      this.emit('listen', port);
      this.log.notice('accepting connections on port %s', port);

      // might be listening on a unix socket too
      if(unix) unix.listen(socket, perm);
    }

    tcp.once('listening', onListen.bind(this));
    tcp.listen.apply(tcp, args);
  // just a unix socket
  }else if(unix) {
    unix.listen(socket, perm);
  }
}
function listen ( ) { var args = [ ] , port = this . conf . get ( ConfigKey . PORT ) , socket = this . conf . get ( ConfigKey . UNIXSOCKET ) , perm = this . conf . get ( ConfigKey . UNIXSOCKETPERM ) , backlog = this . conf . get ( ConfigKey . TCP_BACKLOG ) , cb = typeof arguments [ arguments . length - 1 ] === 'function' ? arguments [ arguments . length - 1 ] : null , tcp , unix ; if ( socket ) { unix = this . _unix = new UnixServer ( this ) ; } // tcp: server.listen(port, [host], [backlog], [callback]) // unix socket: server.listen(path, [callback]) // port zero means don't listen on a tcp port if ( port !== 0 ) { tcp = this . _tcp = new TcpServer ( this ) ; // port comes first args . unshift ( port ) ; // backlog is penultimate argument if ( typeof backlog === 'number' ) { args . push ( backlog ) ; } //console.dir(args); // cb is last argument if ( cb ) args . push ( cb ) ; function onListen ( ) { // for server info, the actual port or socket in use // stored on the state, null if listen was never called // or if the bind failed, could also be a unix socket var addr = tcp . address ( ) ; var port = addr . port ; this . state . addr = addr ; // only write pid if we listen if ( this . _daemonized ) { daemon . pid . write ( this . conf ) ; } this . emit ( 'listen' , port ) ; this . log . notice ( 'accepting connections on port %s' , port ) ; // might be listening on a unix socket too if ( unix ) unix . listen ( socket , perm ) ; } tcp . once ( 'listening' , onListen . bind ( this ) ) ; tcp . listen . apply ( tcp , args ) ; // just a unix socket } else if ( unix ) { unix . listen ( socket , perm ) ; } }
Listen on a port or socket.
Listen on a port or socket .