parent
20ced0ea1e
commit
59b04427d3
@ -46,14 +46,17 @@ exports.connect = exports.createConnection = function(port /* [host], [cb] */) {
|
|||||||
|
|
||||||
/* called when creating new Socket, or when re-using a closed Socket */
|
/* called when creating new Socket, or when re-using a closed Socket */
|
||||||
function initSocketHandle(self) {
|
function initSocketHandle(self) {
|
||||||
self._handle.socket = self;
|
|
||||||
self._handle.onread = onread;
|
|
||||||
|
|
||||||
self._writeRequests = [];
|
self._writeRequests = [];
|
||||||
|
|
||||||
self._flags = 0;
|
self._flags = 0;
|
||||||
self._connectQueueSize = 0;
|
self._connectQueueSize = 0;
|
||||||
self.destroyed = false;
|
self.destroyed = false;
|
||||||
|
|
||||||
|
// Handle creation may be deferred to bind() or connect() time.
|
||||||
|
if (self._handle) {
|
||||||
|
self._handle.socket = self;
|
||||||
|
self._handle.onread = onread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Socket(options) {
|
function Socket(options) {
|
||||||
@ -62,14 +65,10 @@ function Socket(options) {
|
|||||||
stream.Stream.call(this);
|
stream.Stream.call(this);
|
||||||
|
|
||||||
// private
|
// private
|
||||||
if (options && options.handle) {
|
this._handle = options && options.handle;
|
||||||
this._handle = options.handle;
|
|
||||||
} else {
|
|
||||||
this._handle = new TCP;
|
|
||||||
}
|
|
||||||
this.allowHalfOpen = options ? (options.allowHalfOpen || false) : false;
|
|
||||||
|
|
||||||
initSocketHandle(this);
|
initSocketHandle(this);
|
||||||
|
|
||||||
|
this.allowHalfOpen = options && options.allowHalfOpen;
|
||||||
}
|
}
|
||||||
util.inherits(Socket, stream.Stream);
|
util.inherits(Socket, stream.Stream);
|
||||||
|
|
||||||
@ -218,7 +217,9 @@ Socket.prototype.destroy = function(exception) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug('close ' + this.fd);
|
debug('close ' + this.fd);
|
||||||
this._handle.close();
|
if (this._handle) {
|
||||||
|
this._handle.close();
|
||||||
|
}
|
||||||
|
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
if (exception) self.emit('error', exception);
|
if (exception) self.emit('error', exception);
|
||||||
@ -394,7 +395,7 @@ Socket.prototype.connect = function(port /* [host], [cb] */) {
|
|||||||
|
|
||||||
var pipe = isPipeName(port);
|
var pipe = isPipeName(port);
|
||||||
|
|
||||||
if (this.destroyed) {
|
if (this.destroyed || !this._handle) {
|
||||||
this._handle = pipe ? new Pipe() : new TCP();
|
this._handle = pipe ? new Pipe() : new TCP();
|
||||||
initSocketHandle(this);
|
initSocketHandle(this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user