mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Simplify Socket constructor
This commit is contained in:
1 parent
b571900d9c
commit
aa6eaae0aa
1 file changed
+12
-12
+12
-12
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user