diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-03-12 13:04:33 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-03-12 13:06:05 -0800 |
commit | aa6eaae0aa8ba46ca2a25bd0b1e8eec5498df847 (patch) | |
tree | 69aae78a372815fc289a8982d3f247baab2e6816 /lib/net.js | |
parent | b571900d9ccf4d7f64bfa31a6920bdbdcbe45b64 (diff) | |
download | node-new-aa6eaae0aa8ba46ca2a25bd0b1e8eec5498df847.tar.gz |
Simplify Socket constructor
Diffstat (limited to 'lib/net.js')
-rw-r--r-- | lib/net.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/net.js b/lib/net.js index 36fd0cc96f..1b2b348ee2 100644 --- a/lib/net.js +++ b/lib/net.js @@ -356,15 +356,13 @@ function initSocket (self) { self.writable = false; } -function Socket (peerInfo) { +function Socket (fd) { process.EventEmitter.call(this); - if (peerInfo) { + if (fd) { initSocket(this); - this.fd = peerInfo.fd; - this.remoteAddress = peerInfo.remoteAddress; - this.remotePort = peerInfo.remotePort; + this.fd = fd; this.resume(); this.readable = true; @@ -758,18 +756,20 @@ function Server (listener) { self.watcher = new IOWatcher(); self.watcher.host = self; - self.watcher.callback = function (readable, writeable) { + self.watcher.callback = function () { while (self.fd) { var peerInfo = accept(self.fd); if (!peerInfo) return; - var peer = new Socket(peerInfo); - peer.type = self.type; - peer.server = self; - self.emit('connection', peer); + var s = new Socket(peerInfo.fd); + s.remoteAddress = peerInfo.remoteAddress; + s.remotePort = peerInfo.remotePort; + s.type = self.type; + s.server = self; + self.emit('connection', s); // The 'connect' event probably should be removed for server-side // sockets. It's redundent. - peer.emit('connect'); - timeout.active(peer); + s.emit('connect'); + timeout.active(s); } }; } |