|
@ -14,13 +14,25 @@ if (process.env.NODE_DEBUG && /net/.test(process.env.NODE_DEBUG)) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.createServer = function() { |
|
|
|
|
|
return new Server(arguments[0], arguments[1]); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.connect = exports.createConnection = function(port, host) { |
|
|
|
|
|
var s = new Socket(); |
|
|
|
|
|
s.connect(port, host); |
|
|
|
|
|
return s; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Socket(options) { |
|
|
function Socket(options) { |
|
|
if (!(this instanceof Socket)) return new Socket(options); |
|
|
if (!(this instanceof Socket)) return new Socket(options); |
|
|
|
|
|
|
|
|
stream.Stream.call(this); |
|
|
stream.Stream.call(this); |
|
|
|
|
|
|
|
|
// private
|
|
|
// private
|
|
|
if (options.handle) { |
|
|
if (options && options.handle) { |
|
|
this._handle = options.handle; |
|
|
this._handle = options.handle; |
|
|
} else { |
|
|
} else { |
|
|
this._handle = new TCP(); |
|
|
this._handle = new TCP(); |
|
@ -46,6 +58,39 @@ Socket.prototype.setTimeout = function(msecs, callback) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Socket.prototype.setNoDelay = function() { |
|
|
|
|
|
/* TODO implement me */ |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(Socket.prototype, 'readyState', { |
|
|
|
|
|
get: function() { |
|
|
|
|
|
if (this._connecting) { |
|
|
|
|
|
return 'opening'; |
|
|
|
|
|
} else if (this.readable && this.writable) { |
|
|
|
|
|
assert(typeof this.fd === 'number'); |
|
|
|
|
|
return 'open'; |
|
|
|
|
|
} else if (this.readable && !this.writable) { |
|
|
|
|
|
assert(typeof this.fd === 'number'); |
|
|
|
|
|
return 'readOnly'; |
|
|
|
|
|
} else if (!this.readable && this.writable) { |
|
|
|
|
|
assert(typeof this.fd === 'number'); |
|
|
|
|
|
return 'writeOnly'; |
|
|
|
|
|
} else { |
|
|
|
|
|
assert(typeof this.fd !== 'number'); |
|
|
|
|
|
return 'closed'; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(Socket.prototype, 'bufferSize', { |
|
|
|
|
|
get: function() { |
|
|
|
|
|
return this._handle.writeQueueSize; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Socket.prototype.pause = function() { |
|
|
Socket.prototype.pause = function() { |
|
|
this._handle.readStop(); |
|
|
this._handle.readStop(); |
|
|
}; |
|
|
}; |
|
@ -204,6 +249,8 @@ Socket.prototype.connect = function(port, host) { |
|
|
throw new Error("ipv6 addresses not yet supported by libuv"); |
|
|
throw new Error("ipv6 addresses not yet supported by libuv"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ip = ip || '127.0.0.1'; |
|
|
|
|
|
|
|
|
self.remoteAddress = ip; |
|
|
self.remoteAddress = ip; |
|
|
self.remotePort = port; |
|
|
self.remotePort = port; |
|
|
|
|
|
|
|
@ -214,11 +261,11 @@ Socket.prototype.connect = function(port, host) { |
|
|
|
|
|
|
|
|
self._connectReq = self._handle.connect(ip, port); |
|
|
self._connectReq = self._handle.connect(ip, port); |
|
|
|
|
|
|
|
|
if (!self._connectReq) { |
|
|
if (self._connectReq) { |
|
|
|
|
|
self._connectReq.oncomplete = afterConnect; |
|
|
|
|
|
} else { |
|
|
self.destroy(errnoException(errno, 'connect')); |
|
|
self.destroy(errnoException(errno, 'connect')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self._connectReq.oncomplete = afterConnect; |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
@ -330,8 +377,12 @@ function onconnection(clientHandle) { |
|
|
var self = handle.socket; |
|
|
var self = handle.socket; |
|
|
|
|
|
|
|
|
var socket = new Socket({ handle: clientHandle }); |
|
|
var socket = new Socket({ handle: clientHandle }); |
|
|
|
|
|
socket.readable = socket.writable = true; |
|
|
socket.resume(); |
|
|
socket.resume(); |
|
|
|
|
|
|
|
|
|
|
|
self.connections++; |
|
|
|
|
|
socket.server = self; |
|
|
|
|
|
|
|
|
DTRACE_NET_SERVER_CONNECTION(socket); |
|
|
DTRACE_NET_SERVER_CONNECTION(socket); |
|
|
self.emit('connection', socket); |
|
|
self.emit('connection', socket); |
|
|
} |
|
|
} |
|
|