|
|
@ -30,6 +30,17 @@ exports.connect = exports.createConnection = function(port, host /* [cb] */ ) { |
|
|
|
return s; |
|
|
|
}; |
|
|
|
|
|
|
|
/* called when creating new Socket, or when re-using a closed Socket */ |
|
|
|
function initSocketHandle(self) { |
|
|
|
self._handle.socket = self; |
|
|
|
self._handle.onread = onread; |
|
|
|
|
|
|
|
self._writeRequests = []; |
|
|
|
|
|
|
|
self._flags = 0; |
|
|
|
|
|
|
|
self.destroyed = false; |
|
|
|
} |
|
|
|
|
|
|
|
function Socket(options) { |
|
|
|
if (!(this instanceof Socket)) return new Socket(options); |
|
|
@ -42,14 +53,9 @@ function Socket(options) { |
|
|
|
} else { |
|
|
|
this._handle = new TCP(); |
|
|
|
} |
|
|
|
this._handle.socket = this; |
|
|
|
this._handle.onread = onread; |
|
|
|
|
|
|
|
this.allowHalfOpen = options ? (options.allowHalfOpen || false) : false; |
|
|
|
|
|
|
|
this._writeRequests = []; |
|
|
|
|
|
|
|
this._flags = 0; |
|
|
|
initSocketHandle(this); |
|
|
|
} |
|
|
|
util.inherits(Socket, stream.Stream); |
|
|
|
|
|
|
@ -312,6 +318,11 @@ function connectip(self, port, ip) { |
|
|
|
Socket.prototype.connect = function(port, host /* [cb] */) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
if (this.destroyed) { |
|
|
|
this._handle = new TCP(); |
|
|
|
initSocketHandle(this); |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof arguments[2] === 'function') { |
|
|
|
self.on('connect', arguments[2]); |
|
|
|
} |
|
|
|