简体   繁体   English

Node.js中定义的`listen`函数在哪里?

[英]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 我在寻找Node.js内部,我遇到了以下方法定义

//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 . 在Socket对象的listen方法中,有一个(看似)全局函数的调用,也称为listen

listen(self, null, null, null);

Where is this javascript method/function defined? 这个javascript方法/函数定义在哪里? I've scoured all the javascript files in the code-base and can't seem to find it. 我已经搜索了代码库中的所有javascript文件,似乎无法找到它。

(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.) (除了跟踪节点的执行路径并试图理解系统深处使用的模式之外,我没有在这里尝试完成的具体任务。)

https://github.com/joyent/node/blob/b80d11d46b3b2abff1cf1fe887971ea50fd7d497/lib/net.js#L1088 https://github.com/joyent/node/blob/b80d11d46b3b2abff1cf1fe887971ea50fd7d497/lib/net.js#L1088

It's just a function declared lower in the file, which is OK in javascript due to function hoisting. 它只是在文件中声明较低的函数,由于函数提升,在javascript中可以正常。

It's defined farther down in net.js . 它在net.js定义得更远。 As of 0.11.5, it's at line 1089 : 从0.11.5开始, 它位于第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;
  }

  // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM