|
|
@ -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); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|