Browse Source

Simplify Socket constructor

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
aa6eaae0aa
  1. 24
      lib/net.js

24
lib/net.js

@ -356,15 +356,13 @@ function initSocket (self) {
self.writable = false; self.writable = false;
} }
function Socket (peerInfo) { function Socket (fd) {
process.EventEmitter.call(this); process.EventEmitter.call(this);
if (peerInfo) { if (fd) {
initSocket(this); initSocket(this);
this.fd = peerInfo.fd; this.fd = fd;
this.remoteAddress = peerInfo.remoteAddress;
this.remotePort = peerInfo.remotePort;
this.resume(); this.resume();
this.readable = true; this.readable = true;
@ -758,18 +756,20 @@ function Server (listener) {
self.watcher = new IOWatcher(); self.watcher = new IOWatcher();
self.watcher.host = self; self.watcher.host = self;
self.watcher.callback = function (readable, writeable) { self.watcher.callback = function () {
while (self.fd) { while (self.fd) {
var peerInfo = accept(self.fd); var peerInfo = accept(self.fd);
if (!peerInfo) return; if (!peerInfo) return;
var peer = new Socket(peerInfo); var s = new Socket(peerInfo.fd);
peer.type = self.type; s.remoteAddress = peerInfo.remoteAddress;
peer.server = self; s.remotePort = peerInfo.remotePort;
self.emit('connection', peer); s.type = self.type;
s.server = self;
self.emit('connection', s);
// The 'connect' event probably should be removed for server-side // The 'connect' event probably should be removed for server-side
// sockets. It's redundent. // sockets. It's redundent.
peer.emit('connect'); s.emit('connect');
timeout.active(peer); timeout.active(s);
} }
}; };
} }

Loading…
Cancel
Save