Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the `listen` Function in Node.js Defined

I'm poking around the Node.js internals, and I came across the following method definition

//File: node/lib/net.js
Socket.prototype.listen = function() {
  debug('socket.listen');
  var self = this;
  self.on('connection', arguments[0]);
  listen(self, null, null, null);
};

Within the Socket object's listen method, there's a call to a (seemingly) global function, also named listen.

listen(self, null, null, null);

Where is this javascript method/function defined? I've scoured all the javascript files in the code-base and can't seem to find it.

(There's no specific task I'm trying to accomplish here, other than tracing node's execution path and trying to understand the patterns in use deep in the system.)

like image 544
Alan Storm Avatar asked Aug 24 '26 01:08

Alan Storm


1 Answers

It's defined farther down in net.js. As of 0.11.5, it's at line 1089:

function listen(self, address, port, addressType, backlog, fd) {
  if (!cluster) cluster = require('cluster');    

  if (cluster.isMaster) {
    self._listen2(address, port, addressType, backlog, fd);
    return;
  }

  // ...
}
like image 168
Jonathan Lonowski Avatar answered Aug 26 '26 15:08

Jonathan Lonowski